This article mainly introduces the reading method of the Python function key and involves the related operation skills of the Python keyboard event. if you need it, refer to the following example to describe the reading method of the Python function key. Share it with you for your reference. The specific analysis is as follows:
First, getch Gets a. If it is equal to 0 or 224, it indicates that it is a function key, and then getch gets B, then the scan code of this function key is a + (B * 256 ).
Let's take a look at the following example:
Import msvcrt while 1: if msvcrt. kbhit (): # Key pressed a = ord (msvcrt. getch () # get first byte of keyscan code if a = 0 or a = 224: # is it a function key B = ord (msvcrt. getch () # get next byte of key scan code x = a + (B * 256) # cook it. return x # return cooked scancode else: return a # else return ascii code
I hope this article will help you with Python programming.