dMZX Forums: MZX keyboard input - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MZX keyboard input

#1 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 15 July 2012 - 04:51 AM

I have a lot of these useful things I like to use but nowhere to put them all so I'll remember. So I'll post them here

For the likes of events such as BKZXes and DoZs, reusage of this code is pretty much grounds for disqualification, but it might be worthwhile as a reference at the very least during such events.

KEY_CODE/PRESSED MAP



KEY_PRESSED
KEY_PRESSED is like the KEY counter introduced much earlier in MZX's history but at the time it had far more functionality than KEY did, as well as auto-repeat. The auto-repeat makes it incredibly useful for cleanly receiving typed input, however, only one key can be detected at a time with KEY_PRESSED, so it may not be particularly useful for actual gameplay. The auto-repeat runs close to MZX speed 4, even in faster MZX speeds.

You should use KEY_PRESSED when writing joypad mapping utilities (or write something that maps KEY_CODE to KEY_PRESSED... ugh).
  • 32-127 KEY_PRESSED shift translation strings: If shift is not pressed, you index $kpNormal by KEY_PRESSED. If it is, you index $kpShift by KEY_PRESSED.
    set "$kpNormal+32" to " !\"#$%&&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "
    set "$kpShift+32" to " xxxxxx\"xx*+<_>?)!@#$%^&&*(x:x+xxxxxxxxxxxxxxxxxxxxxxxxxxxxx{|}xx~ABCDEFGHIJKLMNOPQRSTUVWXYZxxxxx"
    


  • Key names for KEY_PRESSED (spoilered because it's big).
    Spoiler




KEY_CODE / KEY#
KEY_CODE uses a different system than KEY_PRESSED does, so it needs different mapping strings. It has auto-repeat and like KEY_PRESSED, cannot be checked for multiple values -- however, the KEY# counters, where # is a KEY_CODE value, can. The KEY# counters lack auto-repeat which can make precision input more difficult for the player in some game engines. Detection of keypresses may also be missed by the KEY# counters if a key is pressed and released between frames at slower MZX speeds.

  • Reassignable KEY# wrappers: the idea here is that you set up some counters and strings ahead of time and then use special counters later that take auto-repeat into account, or to see if the key was -just- pressed. These also abstract the actual KEY# counter reads, so you can easily reassign keys at any time.
    Spoiler

This post has been edited by Lachesis: 29 January 2019 - 01:46 AM
Reason for edit: Added missing F12 entry.

"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#2 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 19 November 2012 - 05:00 PM

KEY_CODE / KEYn Names String

Spoiler

This post has been edited by Lachesis: 29 January 2019 - 12:19 AM
Reason for edit: Added missing F12 entry, fixed F11

"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#3 User is offline   darkhog 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 40
  • Joined: 20-November 12
  • Gender:Male

Posted 20 November 2012 - 02:27 PM

What does those numbers on keyboard mean? I think that one is ASCII code, but the second? I am interested in remapping arrow keys to robotic routines (pretty much using IF command) as game I'm writing is not roguelike (though using ASCII gfx), so standard rules doesn't apply there. Player is locked in place so it won't move unwanted and it is set to invisible. I just need to know values returned by KEY_PRESSED for arrow keys.
There are no impossible things, there is only lack of skills.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
~-+=SMZXDraw! The ultimate tool for editing charsets and palettes for SMZX games - FEEDBACK NEEDED!!!=+-~
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Society consists mostly of jerks. We cannot neglect their involvement into building our civilization - without them we
wouldn't have such wonderful inventions like war, money, drugs... or Microsoft Windows.
0

#4 User is offline   Risu2112 

  • I can't get the top off this bottle
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,864
  • Joined: 12-August 01
  • Gender:Male

Posted 20 November 2012 - 04:13 PM

To find out what values KEY_PRESSED returns, just print the value of KEY_PRESSED every cycle with a robot like this:

: "loop"
* "&KEY_PRESSED&"
wait for 1
goto "loop"


The KEY_PRESSED values for the arrow keys are 273, 274, 275, and 276.

* "KEY_PRESSED" // prints "KEY_PRESSED".
* "&KEY_PRESSED&" // prints the value of KEY_PRESSED.
* "('KEY_PRESSED')" // prints the value of the expression 'KEY_PRESSED'. which is in this example the same as the value of KEY_PRESSED.

This post has been edited by Risu2112: 20 November 2012 - 04:19 PM

Respond! Vibrate! Feed back! Resonate!
<Cybersilver> "All my sugestions are for FUTER VERSIONS. Say it with me Fu-ter futer. Yep..."
9-21-2009, SFMZX game play video: HERE
Risu2112
0

#5 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 20 November 2012 - 06:43 PM

Use the image in the first post! It has all of the KEY_CODE (top) and KEY_PRESSED (bottom) values. The KEY_PRESSED (bottom) values are ASCII, the KEY_CODE (top) values are a proprietary set of values that MZX has had for ages.
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#6 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 27 December 2012 - 12:02 AM

KEY_PRESSED <-> KEY_CODE/KEYn
Spoiler

This post has been edited by Lachesis: 29 January 2019 - 12:20 AM
Reason for edit: Added missing F12 entry

"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users