-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathStartConsole.py
More file actions
108 lines (85 loc) · 2.55 KB
/
StartConsole.py
File metadata and controls
108 lines (85 loc) · 2.55 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
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 = 5 # 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
activated = False
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
# Load or bring process forward.
def getProcess():
global processName, handle
# Check if RetroArch isn't running.
# Long string of all procs.
lst = os.popen("tasklist").read()
if processName not in lst:
os.startfile(processName)
else:
try:
# Find window.
win32gui.EnumWindows(enumHandler, None)
# Bring to front.
if handle:
win32gui.SetForegroundWindow(handle)
# Reset hwnd.
handle = None
except Exception as e:
print(e)
# Check if the corrent button combination is pressed on a gamepad,
# and start or bring the process forward.
def checkGamepads(events):
for e in events:
if e.code in toggles:
print(e.code, e.state)
toggles[e.code] = e.state
# Check if all 4 are down.
if all(v != 0 for v in toggles.values()):
# Avoid repetition by resetting the tracker.
for k, v in toggles.items():
toggles[k] = 0
print('starting!')
getProcess()
# Track pressed gamepad buttons.
# Refresh tracker every interval.
while True:
# No gamepads connected. Wait and retry.
if len(inputs.devices.gamepads) == 0:
DEBUG and print('No gamepads connected.')
sleep(delay)
inputs.devices._detect_gamepads()
continue
# Reduce CPU usage.
sleep(0.01)
# Check every gamepad.
for gamepad in inputs.devices.gamepads:
try:
events = gamepad.read()
except Exception as e:
DEBUG and print(e)
# Reset detected gamepads.
inputs.devices.gamepads = []
break
checkGamepads(events)