mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-05-31 07:39:44 +03:00
Pass hotkey on if not used on Windows.
Fixes "Only when Elite: Dangerous is the active app" setting.
This commit is contained in:
parent
0b65beee0d
commit
eca4da57e0
51
hotkey.py
51
hotkey.py
@ -234,11 +234,44 @@ elif platform == 'win32':
|
|||||||
VK_PROCESSKEY= 0xe5
|
VK_PROCESSKEY= 0xe5
|
||||||
VK_OEM_CLEAR = 0xfe
|
VK_OEM_CLEAR = 0xfe
|
||||||
|
|
||||||
|
|
||||||
GetForegroundWindow = ctypes.windll.user32.GetForegroundWindow
|
GetForegroundWindow = ctypes.windll.user32.GetForegroundWindow
|
||||||
GetWindowText = ctypes.windll.user32.GetWindowTextW
|
GetWindowText = ctypes.windll.user32.GetWindowTextW
|
||||||
GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int]
|
GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int]
|
||||||
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
|
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
|
||||||
|
|
||||||
|
def WindowTitle(h):
|
||||||
|
if h:
|
||||||
|
l = GetWindowTextLength(h) + 1
|
||||||
|
buf = ctypes.create_unicode_buffer(l)
|
||||||
|
if GetWindowText(h, buf, l):
|
||||||
|
return buf.value
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
class MOUSEINPUT(ctypes.Structure):
|
||||||
|
_fields_ = [('dx', LONG), ('dy', LONG), ('mouseData', DWORD), ('dwFlags', DWORD), ('time', DWORD), ('dwExtraInfo', ctypes.POINTER(ULONG))]
|
||||||
|
|
||||||
|
class KEYBDINPUT(ctypes.Structure):
|
||||||
|
_fields_ = [('wVk', WORD), ('wScan', WORD), ('dwFlags', DWORD), ('time', DWORD), ('dwExtraInfo', ctypes.POINTER(ULONG))]
|
||||||
|
|
||||||
|
class HARDWAREINPUT(ctypes.Structure):
|
||||||
|
_fields_ = [('uMsg', DWORD), ('wParamL', WORD), ('wParamH', WORD)]
|
||||||
|
|
||||||
|
class INPUT_union(ctypes.Union):
|
||||||
|
_fields_ = [('mi', MOUSEINPUT), ('ki', KEYBDINPUT), ('hi', HARDWAREINPUT)]
|
||||||
|
|
||||||
|
class INPUT(ctypes.Structure):
|
||||||
|
_fields_ = [('type', DWORD), ('union', INPUT_union)]
|
||||||
|
|
||||||
|
SendInput = ctypes.windll.user32.SendInput
|
||||||
|
SendInput.argtypes = [ctypes.c_uint, ctypes.POINTER(INPUT), ctypes.c_int]
|
||||||
|
|
||||||
|
INPUT_MOUSE = 0
|
||||||
|
INPUT_KEYBOARD = 1
|
||||||
|
INPUT_HARDWARE = 2
|
||||||
|
|
||||||
|
|
||||||
class HotkeyMgr:
|
class HotkeyMgr:
|
||||||
|
|
||||||
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx
|
||||||
@ -288,18 +321,20 @@ elif platform == 'win32':
|
|||||||
self.thread = None
|
self.thread = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
fake = INPUT(INPUT_KEYBOARD, INPUT_union(ki = KEYBDINPUT(keycode, keycode, 0, 0, None)))
|
||||||
|
|
||||||
msg = MSG()
|
msg = MSG()
|
||||||
while GetMessage(ctypes.byref(msg), None, 0, 0) != 0:
|
while GetMessage(ctypes.byref(msg), None, 0, 0) != 0:
|
||||||
if msg.message == WM_HOTKEY:
|
if msg.message == WM_HOTKEY:
|
||||||
if config.getint('hotkey_always'):
|
if config.getint('hotkey_always') or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous'):
|
||||||
self.root.event_generate('<<Invoke>>', when="tail")
|
self.root.event_generate('<<Invoke>>', when="tail")
|
||||||
else: # Only trigger if game client is front process
|
else:
|
||||||
h = GetForegroundWindow()
|
# Pass the key on
|
||||||
if h:
|
UnregisterHotKey(None, 1)
|
||||||
l = GetWindowTextLength(h) + 1
|
SendInput(1, fake, ctypes.sizeof(INPUT))
|
||||||
buf = ctypes.create_unicode_buffer(l)
|
if not RegisterHotKey(None, 1, modifiers|MOD_NOREPEAT, keycode):
|
||||||
if GetWindowText(h, buf, l) and buf.value.startswith('Elite - Dangerous'):
|
break
|
||||||
self.root.event_generate('<<Invoke>>', when="tail")
|
|
||||||
elif msg.message == WM_SND_GOOD:
|
elif msg.message == WM_SND_GOOD:
|
||||||
winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous
|
winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous
|
||||||
elif msg.message == WM_SND_BAD:
|
elif msg.message == WM_SND_BAD:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user