Estoy trabajando en un iniciador arcade personalizado en python en Windows. Quiero elegir el sistema y el juego, luego ejecutar el emulador y requerir una cierta combinación de teclas para matar al emulador. Todos mis enganches clave funcionan cuando pruebo con aplicaciones aleatorias, pero cuando realmente lanzo los emuladores (por ejemplo, Nestopia), mis ganchos clave no se disparan. Actualmente estoy usando RegisterHotKey, que obtiene eventos pero no los atajos de teclado. ¿Alguien tiene una idea de cómo instalar algo lo suficientemente bajo como para realmente obtener el evento antes de Nestopia? Aquí está mi código:En Windows, ¿cómo puedo instalar el enganche de teclado global de nivel más bajo posible?
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
no es Python, pero puede ser útil ayudarlo a buscar: http://stackoverflow.com/questions/1465135/deteting-keyboard-hooks – n611x007