forked from phuein/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartConsole.py
More file actions
84 lines (67 loc) · 1.98 KB
/
Copy pathStartConsole.py
File metadata and controls
84 lines (67 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
This script idles in the background,
listening to gamepad (XBox One Controller) button presses,
to activate or bring-to-front RetroArch in Windows 10.
"""
import inputs
from time import sleep, time
import os
import win32gui
DEBUG = False
delay = 3 # Don't repeat anything faster than this in seconds.
t = 0
# Press down all four front buttons to activate.
toggles = {
"BTN_TR": 0,
"BTN_TL": 0,
"ABS_RZ": 0,
"ABS_Z": 0,
}
windowName = "RetroArch"
processName = "retroarch.exe"
handle = None
if DEBUG:
windowName = "Untitled - Notepad"
processName = "notepad.exe"
# Return hwnd or None.
def enumHandler(hwnd, lParam):
global handle
if "RetroArch" in win32gui.GetWindowText(hwnd):
handle = hwnd
while True:
# No gamepads connected. Must have one.
if len(inputs.devices.gamepads) == 0:
DEBUG and print('No gamepads connected.')
sleep(delay)
inputs.devices._detect_gamepads()
continue
# Only the first gamepad to register will catch.
try:
gamepad = inputs.devices.gamepads[0]
events = gamepad.read()
except Exception as e:
DEBUG and print(e)
# Try again.
continue
for e in events:
if e.code in toggles:
toggles[e.code] = e.state
# Check if all 4 are down.
if all(v != 0 for v in toggles.values()):
# Don't retry too fast.
if time() - t < 3:
continue
# Check if RetroArch isn't running.
lst = os.popen("tasklist").read() # Long string of all procs.
if processName not in lst:
os.startfile(processName)
else:
# Find window.
win32gui.EnumWindows(enumHandler, None)
# Bring to front.
if handle:
win32gui.SetForegroundWindow(handle)
# Reset hwnd.
handle = None
# Reset timer.
t = time()