使用the code of PyKeylogger(使用Xlib),我可以检测到大多数键盘键的使用,但是我在检测向上箭头键时遇到了困难。可以将以下行添加到键盘映射中以检测大多数或箭头键:
14: {
0b00000001: ("<pageup>", "shift-pageup"),
0b00000010: ("<left>", "shift-left"),
0b00000100: ("<right>", "shift-right"),
0b00001000: ("<end>", "shift-end"),
0b00010000: ("<down>", "shift-down"),
0b00100000: ("<pagedown>", "shift-PgDn"),
0b01000000: ("<insert>", "shift-insert")
},
如何检测向上箭头键?
答案 0 :(得分:1)
向上箭头
13: {
0b10000000: ("<up>", "shift-up")
},
我得到了PyKeylogger源代码,我找到了可以获取任何密钥代码的地方。
请参阅下面的代码中的print i, o
。它为我提供了13 128
(13 0b10000000
)向上箭头
# aggregate the pressed keys
pressed = []
for i, k in enumerate(keypresses_raw):
o = ord(k)
if o:
#print i, o # this line print code for any pressed key
for byte,key in key_mapping.get(i, {}).iteritems():
if byte & o:
if isinstance(key, tuple): key = key[shift or caps_lock_state]
pressed.append(key)