Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Access keyboard arrow clicks in a script?

A topic by bryanhanson created Nov 21, 2022 Views: 281 Replies: 5
Viewing posts 1 to 3
(+3)

Fantastic Software!  Got my 12 yo grandson working on projects.

Is it possible to programmatically access the arrow keys on the keyboard, i.e. to know when they have been clicked and use that event in a script?  Can't find anything on this except a general mention of "more modern keyboard navigation".  Might be using the wrong keywords...

Thanks!

Developer (1 edit) (+1)

To a limited extent, yes: the "navigate" event is fired at cards when cursor keys are released while in Interact mode. The handler is provided with one of the strings "up", "down", "left", or "right" as an argument. You can also produce these events with swipes by turning on "Nav Gestures" from the Decker menu.

If you don't supply your own, Decker provides a default "on navigate" handler which maps the left and right cursor keys to go["Prev"] and go["Next"], respectively.

There is some discussion of this in the Events section of the  Decker reference manual.

At this time I have avoided exposing any sort of raw keyup/keydown events as it poses portability problems (different OSes, different browser behavior, different country- or user-specific keyboard layouts, etc.), would potentially clash with keys used by Decker itself, and it would result in decks that cannot be used on touchscreen-based devices without a keyboard. The "navigate" event is a compromise.

(1 edit) (+1)

I was just wondering if your thoughts have changed regarding exposing key up/down events? … or perhaps there is a way to accomplish what I’d like to do?

For context, I’m working on a classic NES console-styled RPG with basic controls (d-pad, 2 buttons). I’m going to make it work with mouse/pointer controls regardless (for accessibility), but it would be amazing to control it with the keyboard (which allows for classic controllers to be used with external key mapping applications). Essentially, I’d like to hold down a key to move a character in a given direction on a grid-map (like the movement seen in the path finding tutorial deck). I’m not sure if that is possible though.

I noticed that when shortcut keys are enabled for buttons, the buttons invert when the key is pressed. Even multiple buttons will remain inverted until the keys are released. I believe, up to 6 keys are understood at a time on Win10 OS hardware (the inverting feedback doesn’t always work consistently, but usually 3 keys at a time are tracked properly). I made an alpha-numeric button keyboard in Decker and mashed keys, like a caveman.

I like Decker quite a lot. The lower resolution and limited palette foster creativity, I find. I’ll still work on my RPG regardless of key events being exposed or not. I’m just curious about your thoughts now, being 2 years since your last comment on the matter.

Thank you for sharing such a wonderful program!

Developer(+2)

I haven't changed my mind about this design choice, but I did add an escape-hatch to Web-Decker which offers another possible workaround:  The Forbidden Library includes a module called "kb" which pumps raw key events to the active card. This module will not function in Native-Decker, but that may be acceptable if you otherwise plan to offer graceful degradation to alternative input methods.

(2 edits) (+2)

The Forbidden Library is perfect as an alternative way to play. Thank you for taking the time to build that. There’s so much to learn about Decker!

I’m still of the mind to make the RPG completely mouse driven in Native-Decker (and still accessible with native shortcut key functionality). Playing with a controller/keyboard and holding buttons down with the kb module would just be a bonus. Thank you for sharing that link!

As a side note, reducing my art to 16 colours has been an absolute joy. It really helps to create a cohesive aesthetic. I also love that persistent variables need to exist in widgets. Laying out the game’s state physically on a card with fields and grids is so cool. It encourages you to keep things simple and focus on what matters. Brilliant!

(+2)

Thanks, exactly what I needed to know.  Again, really appreciate this software!  So cool to have something from the "old days" but updated.