Compare commits
3 Commits
7f1d95183e
...
5f14fd11d0
Author | SHA1 | Date | |
---|---|---|---|
|
5f14fd11d0 | ||
|
e342e0d4dd | ||
|
8fe8bc3a0e |
@ -12,6 +12,9 @@ if strings.HasPrefix(message_string, "{KEYDWN}") {
|
|||||||
} else if strings.HasPrefix(message_string, "{KEYUP}") {
|
} else if strings.HasPrefix(message_string, "{KEYUP}") {
|
||||||
key = strings.TrimPrefix(string(message_string), "{KEYUP}")
|
key = strings.TrimPrefix(string(message_string), "{KEYUP}")
|
||||||
k.Write(0, key)
|
k.Write(0, key)
|
||||||
|
} else if strings.HasPrefix(message_string, "{KEYHLD}") {
|
||||||
|
key = strings.TrimPrefix(string(message_string), "{KEYHLD}")
|
||||||
|
k.Write(2, key)
|
||||||
} else{
|
} else{
|
||||||
for _, key := range message_string {
|
for _, key := range message_string {
|
||||||
// write once will simulate keyboard press/release, for long press or release, lookup at Write
|
// write once will simulate keyboard press/release, for long press or release, lookup at Write
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This tool captures keyboard input from /dev/input/eventX and pipes it to the fifo accordingly.
|
This tool captures keyboard input from /dev/input/eventX and pipes it to the fifo accordingly.
|
||||||
|
|
||||||
An escape sequence of QKEYBOARD (QWERTY) will exit the program, but this can be changed via a command line argument.
|
An escape sequence of `qkeyboard` (QWERTY) will exit the program, but this can be changed via a command line argument.
|
||||||
|
|
||||||
|
|
||||||
## Why
|
## Why
|
||||||
@ -18,6 +18,7 @@ Generally a user would be in this mode when not typing extensively.
|
|||||||
--- /tools/rawcapture/rawcapture.py
|
--- /tools/rawcapture/rawcapture.py
|
||||||
|
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
# This tool adapted from https://github.com/whizse/exclusive-keyboard-access by Sven Arvidsson
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import evdev
|
import evdev
|
||||||
@ -65,18 +66,23 @@ print("Using device " + device.fn)
|
|||||||
|
|
||||||
print("Grabbing device for exclusive access.")
|
print("Grabbing device for exclusive access.")
|
||||||
device.grab()
|
device.grab()
|
||||||
print("Enter numbers, press enter (Ctrl-C to exit).")
|
|
||||||
|
|
||||||
write_queue = queue.Queue()
|
write_queue = queue.Queue()
|
||||||
def write_loop():
|
def write_loop():
|
||||||
|
backlog = []
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
while backlog:
|
||||||
|
with open(fifo, "w") as f:
|
||||||
|
f.write(backlog.pop(0))
|
||||||
|
|
||||||
data = write_queue.get()
|
data = write_queue.get()
|
||||||
with open(fifo, "w") as f:
|
with open(fifo, "w") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error writing to fifo: " + str(e))
|
print("Error writing to fifo: " + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
backlog
|
||||||
|
|
||||||
write_thread = threading.Thread(target=write_loop, daemon=True)
|
write_thread = threading.Thread(target=write_loop, daemon=True)
|
||||||
write_thread.start()
|
write_thread.start()
|
||||||
@ -230,11 +236,11 @@ try:
|
|||||||
for event in device.read_loop():
|
for event in device.read_loop():
|
||||||
|
|
||||||
if event.type == evdev.ecodes.EV_KEY:
|
if event.type == evdev.ecodes.EV_KEY:
|
||||||
print(event)
|
if event:
|
||||||
|
print(event)
|
||||||
#e_code = event.code - 1
|
#e_code = event.code - 1
|
||||||
e_code = event.code
|
e_code = event.code
|
||||||
if e_code == 2:
|
|
||||||
break
|
|
||||||
try:
|
try:
|
||||||
key_str = KEYMAP[e_code]
|
key_str = KEYMAP[e_code]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -245,6 +251,8 @@ try:
|
|||||||
quit_if_necessry(log)
|
quit_if_necessry(log)
|
||||||
elif event.value == 0:
|
elif event.value == 0:
|
||||||
key_str = "{KEYUP}" + key_str
|
key_str = "{KEYUP}" + key_str
|
||||||
|
elif event.value == 2:
|
||||||
|
key_str = "{KEYHLD}" + key_str
|
||||||
else:
|
else:
|
||||||
print("Unknown value: " + str(event.value))
|
print("Unknown value: " + str(event.value))
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user