擅长:python、mysql、java
<p>计数器的一般语法是正确的,但是如果您想让一些东西在后台运行并且在控制台之外运行,那么您需要一些类似pyHook的东西。getch()在这种情况下不起作用。在</p>
<pre><code>from pyHook import HookManager
from win32gui import PumpMessages, PostQuitMessage
class Keystroke_Watcher(object):
def __init__(self):
self.hm = HookManager()
self.hm.KeyDown = self.on_keyboard_event
self.hm.HookKeyboard()
def on_keyboard_event(self, event):
try:
if event.KeyID == keycode_youre_looking_for:
self.your_method()
finally:
return True
def your_method(self):
pass
def shutdown(self):
PostQuitMessage(0)
self.hm.UnhookKeyboard()
watcher = Keystroke_Watcher()
PumpMessages()
</code></pre>
<p>它将检测按键,然后您可以增加值。当然,您需要推断代码,但是框架已经为您成功做好了准备。在</p>