Sticky keys

This commit is contained in:
Cat /dev/Nulo 2021-12-13 17:13:56 -03:00
parent 09b85c2c2e
commit 57cdf605f5
2 changed files with 23 additions and 6 deletions

View file

@ -1,5 +1,8 @@
;; port of usb_keyboard.h
; Actually ErrorUndefined
(define sticky-modifier 3)
(define key-a 4)
(define key-b 5)
(define key-c 6)

View file

@ -246,6 +246,7 @@
;; Vectors to store keycodes for the USB frame we are preparing to send.
(define modifiers (vector 0 0 0 0 0))
(define sticky-modifiers (vector 0 0 0 0 0))
(define keycodes-down (vector 0 0 0 0 0 0))
;; For each element of the keycodes-down or modifiers vector, which physical
@ -263,6 +264,11 @@
(vector-set! modifiers (- keycode 1) 1)
(vector-set! keys-for-modifiers (- keycode 1) key))
(define (press-sticky-modifier keycode)
(vector-set! sticky-modifiers (- keycode 1) 1))
(define (release-sticky-modifier keycode)
(vector-set! sticky-modifiers (- keycode 1) 0))
;; Record that a given key resulted in a specific non-modifier press.
(define (press-normal-key keycode key)
(let ((slot (find keycodes-down 0)))
@ -271,17 +277,25 @@
;; Record a key press in the modifiers/keycodes-down vectors for the layout.
(define (press-key key)
(let ((keycode (lookup key)))
(let ((keycode (lookup key))
(sticky (find sticky-modifiers 1)))
;; Sometimes "keycodes" are procedures; in that case we call them with
;; true when the key is pressed and false when it's released.
(if (procedure? keycode)
(keycode #t)
(if (modifier? keycode)
(begin (press-modifier (unmodify keycode) key)
(if (uncombo keycode)
(press-normal-key (uncombo keycode) key)
#f))
(press-normal-key keycode key)))))
(if (uncombo keycode)
(if (= (uncombo keycode) sticky-modifier)
(press-sticky-modifier (unmodify keycode))
(begin
(press-modifier (unmodify keycode) key)
(press-normal-key (uncombo keycode) key)))
(press-modifier (unmodify keycode) key))
(if sticky
(begin (press-modifier (+ sticky 1) key)
(press-normal-key keycode key)
(release-sticky-modifier (+ sticky 1)))
(press-normal-key keycode key))))))
;; Record that a given key being released resulted in a modifier release.
(define (release-modifier keycode key n)