You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
828 B
Python
33 lines
828 B
Python
import time
|
|
from evdev import InputDevice, ecodes, list_devices, UInput
|
|
|
|
# Define key codes for Ctrl and 1
|
|
CTRL = ecodes.KEY_LEFTCTRL
|
|
KEY_1 = ecodes.KEY_1
|
|
|
|
# Define virtual keyboard capabilities (DO NOT include EV_SYN)
|
|
keyboard_events = {
|
|
ecodes.EV_KEY: [CTRL, KEY_1],
|
|
}
|
|
|
|
# Create the virtual input device
|
|
ui = UInput(events=keyboard_events, name="Virtual Ctrl+1 Injector", bustype=ecodes.BUS_USB)
|
|
|
|
try:
|
|
while True:
|
|
print("Sending Ctrl + 1")
|
|
ui.write(ecodes.EV_KEY, CTRL, 1) # Press Ctrl
|
|
ui.write(ecodes.EV_KEY, KEY_1, 1) # Press 1
|
|
ui.syn()
|
|
|
|
time.sleep(0.1)
|
|
|
|
ui.write(ecodes.EV_KEY, KEY_1, 0) # Release 1
|
|
ui.write(ecodes.EV_KEY, CTRL, 0) # Release Ctrl
|
|
ui.syn()
|
|
|
|
time.sleep(2)
|
|
except KeyboardInterrupt:
|
|
print("Exiting...")
|
|
ui.close()
|