summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorAndrés Cuervo <andrescuervor@gmail.com>2023-12-04 21:55:18 +0000
committerAndrés Cuervo <andrescuervor@gmail.com>2023-12-04 21:55:18 +0000
commitacdc859ed816f71f2b99ed49e0d37112d17171e9 (patch)
tree84893803f3b054f5a4d51cf481c9ddfe03ca9c05 /virtual-programs
parentRemove readCount debugging (diff)
downloadfolk-acdc859ed816f71f2b99ed49e0d37112d17171e9.tar.gz
folk-acdc859ed816f71f2b99ed49e0d37112d17171e9.zip
Integrate modifiers, fix esc-restart
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/esc-restart.folk2
-rw-r--r--virtual-programs/keyboard.folk39
2 files changed, 34 insertions, 7 deletions
diff --git a/virtual-programs/esc-restart.folk b/virtual-programs/esc-restart.folk
index ee8aa847..d94f2323 100644
--- a/virtual-programs/esc-restart.folk
+++ b/virtual-programs/esc-restart.folk
@@ -1,3 +1,3 @@
-When keyboard claims key ESC is down with modifiers alt {
+When keyboard /k/ claims key ESC is down with modifiers alt {
exec sudo systemctl restart folk
}
diff --git a/virtual-programs/keyboard.folk b/virtual-programs/keyboard.folk
index 8c2c85b3..080eb679 100644
--- a/virtual-programs/keyboard.folk
+++ b/virtual-programs/keyboard.folk
@@ -81,7 +81,7 @@ foreach keyboard $keyboardDevices {
Start process "keyboard-$eventPath" {
source "pi/KeyCodes.tcl"
Wish $::thisProcess shares statements like \
- [list keyboard /k/ claims key /k/ is /v/]
+ [list keyboard /kb/ claims key /k/ is /t/ with modifiers /m/]
variable evtBytes 16
variable evtFormat iissi
if {[exec getconf LONG_BIT] == 64} {
@@ -90,18 +90,45 @@ foreach keyboard $keyboardDevices {
}
set keyboardSpecifier $eventPath
variable eventPathChannel [open $eventPath r]
+ set keyStates [list up down repeat]
+ set modifiers [dict create \
+ shift 0 \
+ ctrl 0 \
+ alt 0 \
+ ]
while 1 {
binary scan [read $eventPathChannel $evtBytes] $evtFormat tvSec tvUsec type code value
if {$type > 0x04} {
set eventPathChannel [open $eventPath r]
binary scan [read $eventPathChannel $evtBytes] $evtFormat tvSec tvUsec type code value
}
- if {$type == 0x01 && ($value == 1) || ($value == 2)} {
- set key [keyFromCode $code 0]
- # puts "shift: [string match *SHIFT $key] | $key"
+ if {$type == 0x01} {
+ set shift [dict get $modifiers shift]
+ set key [keyFromCode $code $shift]
+ set keyState [lindex $keyStates $value]
+
+ # dict set modifiers shift 0
+ # dict set modifiers alt 0
+ # dict set modifiers ctrl 0
+
+ set isDown [expr {$keyState != "up"}]
+ if {[string match *SHIFT $key]} {
+ dict set modifiers shift $isDown
+ }
+ if {[string match *CTRL $key]} {
+ dict set modifiers ctrl $isDown
+ }
+ if {[string match *ALT $key]} {
+ dict set modifiers alt $isDown
+ }
+
+ set heldModifiers [dict keys [dict filter $modifiers value 1]]
+ puts "shift: [string match *SHIFT $key] | $key"
+ puts "modifiers: $heldModifiers"
+
puts "got key event ($keyboardSpecifier): $code => $key | $value"
- Retract keyboard $keyboardSpecifier claims key /k/ is /t/
- Assert keyboard $keyboardSpecifier claims key [keyFromCode $code false] is [list $value]
+ Retract keyboard $keyboardSpecifier claims key /k/ is /t/ with modifiers /m/
+ Assert keyboard $keyboardSpecifier claims key [list $key] is [list $keyState] with modifiers [list $heldModifiers]
Step
}
}