-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymultiplexertest.py
64 lines (50 loc) · 1.5 KB
/
keymultiplexertest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
# SPDX-License-Identifier: MIT
# Simple demo of the DRV2605 haptic feedback motor driver.
# Will play all 123 effects in order for about a half second each.
import time
import board
import busio
from glove import Glove
from pynput.keyboard import Key, KeyCode, Listener
glove = Glove()
fingers = [0]*5
def update_fingers():
glove.set_fingers(fingers)
def on_press(key):
#print(str(key) + " pressed")
if key == KeyCode.from_char('a'):
#print('in a if')
fingers[0] = 1.0
if key == KeyCode.from_char('s'):
fingers[1] = 1.0
if key == KeyCode.from_char('d'):
fingers[2] = 1.0
if key == KeyCode.from_char('f'):
fingers[3] = 1.0
if key == KeyCode.from_char('g'):
fingers[4] = 1.0
update_fingers()
def on_release(key):
#print(str(key) + " released")
if key == Key.esc:
glove.stop_fingers()
# Stop listener
return False
if key == KeyCode.from_char('a'):
fingers[0] = 0.0
if key == KeyCode.from_char('s'):
fingers[1] = 0.0
if key == KeyCode.from_char('d'):
fingers[2] = 0.0
if key == KeyCode.from_char('f'):
fingers[3] = 0.0
if key == KeyCode.from_char('g'):
fingers[4] = 0.0
update_fingers()
if __name__ == '__main__':
# Collect events until released
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()