Author Topic: Capturing Keystrokes misses the arrow keys  (Read 124 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

Capturing Keystrokes misses the arrow keys
« on: December 13, 2025, 08:33:56 PM »
Alright, I am working on a mini game, basically the player is prompted which arrow key to press by a view with a changestate. I am attempting to use a handleEvent method in the room script and it seems to be working... just not for the arrow keys.
Code: [Select]
(instance RoomScript of Script
(properties)
  (method (handleEvent pEvent)
  (super handleEvent: pEvent)
     (Print addText: "event" init:)
(switch (pEvent type?)
(evJOYSTICK
(switch (pEvent message?)
(JOY_UP
            (Print addText: "up" init:)
)
(JOY_DOWN
            (Print addText: "down" init:)
)
(JOY_LEFT
            (Print addText: "left" init:)
)
(JOY_RIGHT
            (Print addText: "right" init:)
)
)
(pEvent claimed: TRUE)
)
(evKEYBOARD
(switch (pEvent message?)
(KEY_TAB
            (Print addText: "tab" init:) 
)
(KEY_SPACE
            (Print addText: "space" init:) 
)
(KEY_8
            (Print addText: "8" init:) 
)
(KEY_UP
            (Print addText: "up" init:) 
)
(KEY_LEFT
            (Print addText: "left" init:) 
)
(KEY_DOWN
            (Print addText: "down" init:) 
)
(KEY_RIGHT
            (Print addText: "right" init:) 
)
)
(pEvent claimed: TRUE)
)
(else  (pEvent claimed: TRUE))
)
(return)
  ); ends method
); ends instance
When I run the game, I can press space, and tab and both of them print out two messages, one letting me know an event took place, and a second letting me know the button was pressed. However when I click on an arrow button, I get no response, not even the event has happened message

From the keys.sh file KEY_NUMPAD8 and KEY_UP are defined the same $4800... I tried them both with no response.

What is it that am I missing here?

*The same behavior can be seen in the titlescreen script, any keyboard event should trigger the window... and most do, but not the arrows
« Last Edit: December 13, 2025, 09:13:46 PM by Cloudee1 »


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Kawa

Re: Capturing Keystrokes misses the arrow keys
« Reply #1 on: December 14, 2025, 04:57:49 AM »
I might have to blame your way of reporting the press. Using some Display calls gave me better results.

Code: [Select]
(method (handleEvent pEvent)
(super handleEvent: pEvent)
(if (not (pEvent claimed?))
(switch (pEvent type?)
(evJOYSTICK
(Display {Direction event} dsCOORD 16 16 dsCOLOR clWHITE dsBACKGROUND clBLACK)
(switch (pEvent message?)
(JOY_UP (Display {up______} dsCOORD 16 24 dsCOLOR clWHITE dsBACKGROUND clBLACK))
(JOY_DOWN (Display {down___} dsCOORD 16 24 dsCOLOR clWHITE dsBACKGROUND clBLACK))
(JOY_LEFT (Display {left___} dsCOORD 16 24 dsCOLOR clWHITE dsBACKGROUND clBLACK))
(JOY_RIGHT (Display {right} dsCOORD 16 24 dsCOLOR clWHITE dsBACKGROUND clBLACK))
)
)
(else
(Display {Other event______} dsCOORD 16 16 dsCOLOR clWHITE dsBACKGROUND clBLACK)
(Display {?_______________} dsCOORD 16 24 dsCOLOR clWHITE dsBACKGROUND clBLACK)
)
)
)
)

Offline Cloudee1

Re: Capturing Keystrokes misses the arrow keys
« Reply #2 on: Yesterday at 06:45:25 PM »
So it turns out, the arrow keys and the number pad keys are not a part of the key handler, but the direction handler... and maps to event type 68... anyway, here is what worked.
I created an egoHandleEvent Script and then set any old random view to use it when the time came. I left the joystick event in there, but I don't have a joystick so I don't know if that actually works, but the arrow key presses are now captured. In my case, I am setting a couple of variables, pressed tells the doit method that they have pressed an arrow key and to pick the next direction, while the entered variable tells me what direction they pressed as it corresponds to a views loops

Code: [Select]
(instance egoHandleEvent of Script
(properties)
(method (init)
(super init: &rest)
(gOldDH addToFront: self)
)

(method (dispose)
(gOldDH delete: self)
(super dispose:)
)

(method (handleEvent pEvent)
  ;  (Printf "Event Type: %d" (pEvent type?))
  ;  (Printf "Event Message Type: %d" (pEvent message?))
(switch (pEvent type?)
(evJOYSTICK
(switch (pEvent message?)
(JOY_RIGHT (= pressed 1)(= entered  1))
(JOY_LEFT (= pressed 1)(= entered 2))
(JOY_UP (= pressed 1) (= entered 4))
(JOY_DOWN (= pressed 1)(= entered 3))
)
    (pEvent claimed: 1)
)
(68
(switch (pEvent message?)
(1 (= pressed 1) (= entered 4)); pressed Up...
(7 (= pressed 1) (= entered 2)); pressed left
(3 (= pressed 1) (= entered 1)); pressed right
(5 (= pressed 1) (= entered 3)); pressed down
)
(pEvent claimed: 1)
)
(else
(pEvent claimed: 1)
)
)
(super handleEvent: pEvent)
) ; ends method
)
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline lskovlun

Re: Capturing Keystrokes misses the arrow keys
« Reply #3 on: Yesterday at 10:08:18 PM »
So the type 68 is because later SCI sets the direction bit instead (using OR) instead of assigning the value evJOYSTICK. This is a change from older SCI which was implemented in ScummVM years ago. Supposedly it helps with mouse emulation on machines without a mouse. The User object has a mapKeyToDir (lowercase m) property that suppresses the conversion from evKEYBOARD to evJOYSTICK events if set to zero.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.043 seconds with 21 queries.