python获取键盘按键_在Python中获取按键的键盘代码

正如synthesizerpatel所说,我需要进入一个较低的层次。在

使用pyusb:import usb.core, usb.util, usb.control

dev = usb.core.find(idVendor=0x045e, idProduct=0x0780)

try:

if dev is None:

raise ValueError('device not found')

cfg = dev.get_active_configuration()

interface_number = cfg[(0,0)].bInterfaceNumber

intf = usb.util.find_descriptor(

cfg, bInterfaceNumber=interface_number)

dev.is_kernel_driver_active(intf):

dev.detach_kernel_driver(intf)

ep = usb.util.find_descriptor(

intf,

custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN)

while True:

try:

# lsusb -v : find wMaxPacketSize (8 in my case)

a = ep.read(8, timeout=2000)

except usb.core.USBError:

pass

print a

except:

raise

这将给您一个输出:array('B', [0, 0, 0, 0, 0, 0, 0, 0])

阵列位置:

0:和修改键(1-控制键,2-移位键,4-元键,8-超级键)

1: 不知道

2-7:按键的按键代码。在

所以:

^{pr2}$

是:ctrl+shift+numpad1+numpad2+numpad3+numpad4+numpad5+numpad6

如果有人知道第二个索引存储了什么,那就太棒了。在

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值