Community

SCI Programming => SCI Syntax Help => Topic started by: Cloudee1 on December 13, 2025, 08:33:56 PM

Title: Capturing Keystrokes misses the arrow keys
Post by: Cloudee1 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
Title: Re: Capturing Keystrokes misses the arrow keys
Post by: Kawa 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)
)
)
)
)
Title: Re: Capturing Keystrokes misses the arrow keys
Post by: Cloudee1 on December 20, 2025, 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
)
Title: Re: Capturing Keystrokes misses the arrow keys
Post by: lskovlun on December 20, 2025, 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.