-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'g-mode-hotkey-support'
- Loading branch information
Showing
7 changed files
with
120 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
WMI>=1.5.1 | ||
PySide6>=6.2.2.1 | ||
windows-toasts>=1.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import threading | ||
import win32con | ||
from ctypes import * | ||
from ctypes.wintypes import * | ||
from PySide6.QtCore import * | ||
|
||
G_MODE_KEY = 0x80 | ||
|
||
_STOP_SIGNAL_CODE = 0x9AB10000 # This number was picked randomly | ||
|
||
class HotKey(QThread): | ||
def __init__(self, key: int, keyPressedSignal: Signal): | ||
super(HotKey, self).__init__() | ||
self.keyPressedSignal = keyPressedSignal | ||
self.key = key | ||
|
||
def run(self): | ||
self.nativeThreadId = threading.get_native_id() | ||
user32 = windll.user32 | ||
|
||
if not user32.RegisterHotKey(None, 1, 0, self.key): | ||
print(f"Could not register hot key {self.key}") | ||
return | ||
msg = MSG() | ||
|
||
while user32.GetMessageA(byref(msg), None, 0, 0): | ||
if msg.message == win32con.WM_USER and msg.wParam == _STOP_SIGNAL_CODE: | ||
break | ||
if msg.message == win32con.WM_HOTKEY and msg.wParam == 1: | ||
self.keyPressedSignal.emit() | ||
user32.UnregisterHotKey(None, 1) | ||
|
||
def stop(self): | ||
windll.user32.PostThreadMessageW(self.nativeThreadId, win32con.WM_USER, _STOP_SIGNAL_CODE, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters