From 9b9fc04b0c342d05be511c3d838ecb2083b397b1 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Mon, 21 Feb 2022 14:13:21 -0800 Subject: [PATCH] Revise keys. --- ueforth/common/grf.fs | 13 ++++++------- ueforth/common/grf_test.fs | 12 ++++++++++-- ueforth/windows/grf.fs | 14 +++++++++++--- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ueforth/common/grf.fs b/ueforth/common/grf.fs index dc532e9..7cff02c 100644 --- a/ueforth/common/grf.fs +++ b/ueforth/common/grf.fs @@ -27,13 +27,12 @@ \ mouse-x ( -- n ) \ mouse-y ( -- n ) \ last-key ( -- n ) -\ last-keysym ( -- n ) -\ last-keycode ( -- n ) +\ last-char ( -- n ) \ pressed? ( k -- f ) \ event ( -- n ) \ Event constants: -\ UNKNOWN TIMEOUT RESIZED EXPOSED -\ MOTION PRESSED RELEASED FINISHED +\ UNKNOWN TIMEOUT RESIZED EXPOSED MOTION +\ PRESSED RELEASED TYPED FINISHED \ Key/Button constants: \ LEFT-BUTTON MIDDLE-BUTTON RIGHT-BUTTON @@ -47,7 +46,8 @@ vocabulary internals 4 constant MOTION 5 constant PRESSED 6 constant RELEASED -7 constant FINISHED +7 constant TYPED +8 constant FINISHED 255 constant LEFT-BUTTON 254 constant MIDDLE-BUTTON @@ -56,8 +56,7 @@ vocabulary internals 0 value mouse-x 0 value mouse-y 0 value last-key -0 value last-keysym -0 value last-keycode +0 value last-char 0 value event 0 value width 0 value height diff --git a/ueforth/common/grf_test.fs b/ueforth/common/grf_test.fs index 26e6aff..72f6b1a 100644 --- a/ueforth/common/grf_test.fs +++ b/ueforth/common/grf_test.fs @@ -18,8 +18,16 @@ grf : run begin wait - 0 to color - 0 0 width height box + PRESSED event = if + ." DOWN: " last-key . cr + then + RELEASED event = if + ." UP: " last-key . cr + then + TYPED event = if + ." CHAR: " last-char . cr + then + 0 to color 0 0 width height box LEFT-BUTTON pressed? if $ccccff else $ffccff then to color mouse-x mouse-y height heart flip diff --git a/ueforth/windows/grf.fs b/ueforth/windows/grf.fs index d80b2a7..e681845 100644 --- a/ueforth/windows/grf.fs +++ b/ueforth/windows/grf.fs @@ -85,19 +85,27 @@ cell allocate throw to backbuffer 0 exit then WM_KEYDOWN msg = if + w 0 max 255 min to last-key + 1 last-key key-state! PRESSED to event then WM_KEYUP msg = if + w 0 max 255 min to last-key + 0 last-key key-state! RELEASED to event then WM_CHAR msg = if + w to last-char + TYPED to event + 0 exit then msg msg>button if l GET_X_LPARAM to mouse-x l GET_Y_LPARAM to mouse-y - msg msg>pressed msg msg>button key-state! - msg msg>button to last-keycode - msg msg>pressed if PRESSED else RELEASED then to event + msg msg>button to last-key + msg msg>pressed dup last-key key-state! + if PRESSED else RELEASED then to event + 0 exit then WM_MOUSEMOVE msg = if l GET_X_LPARAM to mouse-x