我正在开发一个PyKDE4 4/PyQt4 4应用程序自动键,我注意到当我向程序发送CTRL+C时,键盘中断直到我通过ie与应用程序交互后才会被处理。单击菜单项或更改复选框。
lfaraone@stone:~$ /usr/bin/autokey
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/popupmenu.py", line 113, in on_triggered
def on_triggered(self):
KeyboardInterrupt
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/configwindow.py", line 423, in mousePressEvent
def mousePressEvent(self, event):
KeyboardInterrupt尽管在/usr/bin/autokey中有以下内容,但仍然是这样的:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from autokey.autokey import Application
a = Application()
try:
a.main()
except KeyboardInterrupt:
a.shutdown()
sys.exit(0)为什么KeyboardInterrupt没有被捕获:
使用Python2.6运行Ubuntu9.04。
发布于 2009-08-31 11:31:07
尝试这样做:
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)在调用a.main()之前。
更新:请记住,Ctrl可用于应用程序中的复制。最好在Qt中使用Ctrl+\,这将导致事件循环终止,而应用程序关闭。
https://stackoverflow.com/questions/1353823
复制相似问题