4

嘿,我才真正开始使用 Python,我决定制作捕捉某些键的程序,我在网上找到了捕捉鼠标点击的源代码,并决定从它开始,这是代码:

import Xlib
import Xlib.display

display = Xlib.display.Display(':0')
root = display.screen().root
root.change_attributes(event_mask = Xlib.X.ButtonPressMask | Xlib.X.ButtonReleaseMask)

while True:
    event = root.display.next_event()
    print "hi"

这是我运行它时得到的错误:

miles@miles:~/py/keynotify$ python x.py
Xlib.protocol.request.QueryExtension
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 173, sequence_number = 9, major_opcode = 2, minor_opcode = 0
^CTraceback (most recent call last):
  File "x.py", line 9, in <module>
    event = root.display.next_event()
  File "/usr/lib/pymodules/python2.7/Xlib/protocol/display.py", line 171, in next_event
    self.send_and_recv(event = 1)
  File "/usr/lib/pymodules/python2.7/Xlib/protocol/display.py", line 502, in send_and_recv
rs, ws, es = select.select([self.socket], writeset, [], timeout)
KeyboardInterrupt

非常感谢任何帮助!

4

0 回答 0