Python功能键的读取方法

yipeiwu_com6年前Python基础

本文实例讲述了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

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

相关文章

python转换字符串为摩尔斯电码的方法

本文实例讲述了python转换字符串为摩尔斯电码的方法。分享给大家供大家参考。具体实现方法如下: chars = ",.0123456789?abcdefghijklmnop...

Python饼状图的绘制实例

Python饼状图的绘制实例

import numpy as np import matplotlib.pyplot as plt labels = 'A', 'B', 'C', 'D' fracs = [15,...

python的pytest框架之命令行参数详解(下)

python的pytest框架之命令行参数详解(下)

前言 上篇说到命令行执行测试用例的部分参数如何使用?今天将继续更新其他一些命令选项的使用,和pytest收集测试用例的规则! pytest执行用例命令行参数 --collect-on...

python pytest进阶之fixture详解

前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytes...

详解Python编程中time模块的使用

一、简介 time模块提供各种操作时间的函数 说明:一般有两种表示时间的方式: 第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的 第二种以...