-
Notifications
You must be signed in to change notification settings - Fork 1
/
big_keyboard.py
43 lines (33 loc) · 997 Bytes
/
big_keyboard.py
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
#!/usr/bin/env python3
import datetime
import time
import subprocess
import uinput
from gpiozero import Button
print('MUSS ALS SUDO GESTARTET WERDEN!!')
# Sleep this long between polling for events:
EVENT_WAIT_SLEEP_SECONDS = 0.1
# Define Keys which should be emulated
KEY_MAPPING = {
0: uinput.KEY_LEFT,
1: uinput.KEY_RIGHT,
}
# Make sure uinput kernel module is loaded.
subprocess.check_call(['modprobe', 'uinput'])
# Configure virtual keyboard.
device = uinput.Device(KEY_MAPPING.values())
# Define button for GPIO3
button1 = Button(2)
button2 = Button(3)
while True:
if button1.is_pressed:
device.emit_click(KEY_MAPPING[1])
currentDT = datetime.datetime.now()
print("Button Right is pressed")
print(str(currentDT))
if button2.is_pressed:
device.emit_click(KEY_MAPPING[0])
currentDT = datetime.datetime.now()
print("Button Left is pressed")
print(str(currentDT))
time.sleep(EVENT_WAIT_SLEEP_SECONDS)