मैं विंडोज पर पायथन में एक कस्टम आर्केड लॉन्चर पर काम कर रहा हूं। मैं सिस्टम और गेम चुनना चाहता हूं, फिर एमुलेटर लॉन्च करें - और एमुलेटर को मारने के लिए एक निश्चित कुंजी संयोजन की आवश्यकता है। यादृच्छिक अनुप्रयोगों के साथ परीक्षण करते समय मेरे सभी महत्वपूर्ण हुक काम करते हैं, लेकिन जब मैं वास्तव में अनुकरणकर्ताओं (जैसे नेस्टोपिया) लॉन्च करता हूं, तो मेरे मुख्य हुक आग लगने में असफल होते हैं। मैं वर्तमान में RegisterHotKey का उपयोग कर रहा हूं, जो घटनाओं को प्राप्त करता है लेकिन हॉटकी नहीं। किसी को भी पता है कि वास्तव में नेस्टोपिया से पहले घटना को प्राप्त करने के लिए पर्याप्त कुछ कैसे स्थापित करें? यहां मेरा कोड है:विंडोज़ पर, मैं निम्नतम स्तर के वैश्विक कीबोर्ड हुक को कैसे स्थापित कर सकता हूं?
import ctypes
import win32con
from ctypes import wintypes
from ctypes import byref
user32 = ctypes.windll.user32
class SimpleKeyboardHook:
def getNextId(self):
SimpleKeyboardHook._id += 1
return SimpleKeyboardHook._id
# modifiers is a bitmask with win32con.[MOD_SHIFT, MOD_ALT, MOD_CONTROL, MOD_WIN]
def waitFor(self, key, modifiers):
# coerce to 0 if necessary
modifiers = modifiers or 0
id = self.getNextId()
hk = user32.RegisterHotKey(None, id, modifiers, key)
print "register hotkey: ",hk
if not hk:
print "Unable to register hotkey for key ", key
return False
print "registered id", id
try:
msg = wintypes.MSG()
while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
print "got message",msg.message,"which is not",win32con.WM_HOTKEY
if msg.message == win32con.WM_HOTKEY:
print "got hotkey"
if msg.wParam == id:
print "found proper hotkey"
return True
user32.TranslateMessage(byref(msg))
user32.DispatchMessageA(byref(msg))
finally:
user32.UnregisterHotKey(None, id)
return False
SimpleKeyboardHook._id = 0
यह पाइथन नहीं है लेकिन यह आपको खोज करने में सहायता करने के लिए अंतर्दृष्टिपूर्ण हो सकता है: http://stackoverflow.com/questions/1465135/detecting-keyboard-hooks – n611x007