Modifier keys.

This commit is contained in:
Phil Hagelberg 2019-07-01 22:00:43 -07:00
parent aec730cbea
commit b888612132
3 changed files with 26 additions and 9 deletions

View file

@ -40,8 +40,12 @@
(define key-tab 43) (define key-tab 43)
(define key-enter 40) (define key-enter 40)
(define mod-ctrl #x01) (define (modifier? keycode) (list? keycode))
(define mod-shift #x02) (define (modify keycode) (list keycode))
(define mod-alt #x04) (define (unmodify keycode) (car keycode))
(define mod-gui #x08)
(define mod-fn #x16) (define mod-ctrl (modify #x01))
(define mod-shift (modify #x02))
(define mod-alt (modify #x04))
(define mod-gui (modify #x08))
(define mod-fn (modify #x16))

View file

@ -54,12 +54,22 @@
(define (layout-lookup key-position) (define (layout-lookup key-position)
(vector-ref layout key-position)) (vector-ref layout key-position))
(define (keycode-for keys-pressed key-count keycodes)
(let ((code (vector-ref layout (vector-ref keys-pressed key-count))))
;; (printf "keycode ~s ~s~n" code key-count)
(if (modifier? code)
(begin (vector-set! keycodes 0 (+ (vector-ref keycodes 0)
(unmodify code)))
#f)
code)))
(define (keycodes-for keys-pressed key-count keycodes) (define (keycodes-for keys-pressed key-count keycodes)
(if (= 0 key-count) (if (= 0 key-count)
(vector->list keycodes) (vector->list keycodes)
(let ((keycode (vector-ref layout (vector-ref keys-pressed key-count)))) (let ((keycode (keycode-for keys-pressed key-count keycodes)))
;; (printf "keycode ~s ~s~n" keycode key-count) (if keycode
(vector-set! keycodes key-count keycode) (vector-set! keycodes key-count keycode)
#f)
(keycodes-for keys-pressed (- key-count 1) keycodes)))) (keycodes-for keys-pressed (- key-count 1) keycodes))))
(define (loop) (define (loop)

View file

@ -41,7 +41,10 @@
(include "keycodes.scm") (include "keycodes.scm")
;; pair of pins/keycodes ;; pair of pins/keycodes
`(((1) . (0 ,key-w 0 0 0 0 0)) `(((1) . (0 ,key-w 0 0 0 0 0))
((2) . (0 ,key-e 0 0 0 0 0)))) ((2) . (0 ,key-e 0 0 0 0 0))
((27) . (4 0 0 0 0 0 0))
((36 4) . (2 ,key-t 0 0 0 0 0))
((36 4 6) . (2 ,key-t ,key-y 0 0 0 0))))
(define test-data (make-test-data)) (define test-data (make-test-data))