I am working on a custom arcade installation on python on Windows. I want to select a system and a game, and then start the emulator - and in order to kill the emulator, a certain key combination is required. All my key hooks work when testing with random applications, but when I run emulators (like Nestopia), my key hooks do not work. I am currently using RegisterHotKey, which receives events, but not hotkeys. Does anyone have an idea how to set something low enough to actually get an event before Nestopia? Here is my code:
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
source share