Home > Backend Development > Python Tutorial > Python功能键的读取方法

Python功能键的读取方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:17:41
Original
1418 people have browsed it

本文实例讲述了Python功能键的读取方法。分享给大家供大家参考。具体分析如下:

先getch一下得到a,如果等于0或者224,就说明是功能键,再getch下一个得到b,那么这个功能键的扫描码就是a+(b*256) 。

可以看看下面这个例子:

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
Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template