Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:01 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : KEYDOWN(7)

Author Message
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 10:27pm 07 Sep 2020
Copy link to clipboard 
Print this post

ICYMI, reading through the 5.05.05 User Manual, there is this little gem tucked away (looks like this capability first appeared in 5.05.04):

  Quote  KEYDOWN(7) will give any modifier keys that are pressed. These keys do
not add to the count in keydown(0)


KEYDOWN(7) returns a single decimal value which represents a bitmap of the keyboard modifier keys, as follows:


|    8    |    7    |    6    |    5    |    4    |    3    |    2    |    1    |
|  RSHFT  |   RWIN  |  RCTRL  |   RALT  |  LSHFT  |   LWIN  |  LCTRL  |   LALT  |



This snippet is one way you can read and act on the pressed modifier key(s). If it looks a little confusing, it's because I am following a U-shaped path around a physical keyboard.


do
modstr$=BIN$(keydown(7),8) 'pad returned string to 8 bits
modkeys$ = ""
IF MID$(modstr$,5,1)="1" THEN modkeys$=modkeys$+" LSHFT"
IF MID$(modstr$,7,1)="1" THEN modkeys$=modkeys$+" LCTRL"
IF MID$(modstr$,6,1)="1" THEN modkeys$=modkeys$+" LWIN"
IF MID$(modstr$,8,1)="1" THEN modkeys$=modkeys$+" LALT"
IF MID$(modstr$,4,1)="1" THEN modkeys$=modkeys$+" RALT"
IF MID$(modstr$,2,1)="1" THEN modkeys$=modkeys$+" RWIN"
IF MID$(modstr$,3,1)="1" THEN modkeys$=modkeys$+" RCTRL"
IF MID$(modstr$,1,1)="1" THEN modkeys$=modkeys$+" RSHFT"
print modstr$ + modkeys$
loop

Edited 2020-09-08 08:32 by jpusztai
Enjoy Every Sandwich / Joe P.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 10:45pm 07 Sep 2020
Copy link to clipboard 
Print this post

KEYDOWN(7) is indeed very useful but you don't have to do all that string handling:
do
 cls
 modkey = keydown(7)
 if modkey and   1 then ? @(100,100) "L-Alt "
 if modkey and   2 then ? @(150,100) "L-Ctrl"
 if modkey and   4 then ? @(200,100) "L-Win "
 if modkey and   8 then ? @(250,100) "L-Shft"
 if modkey and  16 then ? @(300,100) "R-Alt "
 if modkey and  32 then ? @(350,100) "R-Ctrl"
 if modkey and  64 then ? @(400,100) "R-Win "
 if modkey and 128 then ? @(450,100) "R-Shft"
 pause 50
loop

For something I'm working on, I did NOT want the fire key to auto-repeat. KEYDOWN(7) solved that for me by letting me use the Ctrl key to fire, with some minor code to react only to the initial key press.

Matherp and team have definitely created a masterpiece for us to explore and play with.
Edited 2020-09-08 08:53 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 10:50pm 07 Sep 2020
Copy link to clipboard 
Print this post

I was 100% sure there was a more elegant way to do this :)
Enjoy Every Sandwich / Joe P.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 10:55pm 07 Sep 2020
Copy link to clipboard 
Print this post

That's the cool thing here on this forum. There are some seriously skilled programmers to learn stuff from!
Visit Vegipete's *Mite Library for cool programs.
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 11:13pm 07 Sep 2020
Copy link to clipboard 
Print this post

  vegipete said  KEYDOWN(7) is indeed very useful...I did NOT want the fire key to auto-repeat...Matherp and team have definitely created a masterpiece for us to explore and play with.


Agree on all points :)

I had exactly the same issue i.e. I need a "single shot" firing button, and I typically map Z, X and R-Shft for Space Invader type games on my MAME rig, so this is exactly what I was looking for. And, on the CMM2, I won't even have to turn of Windoze's annoying "Sticky Keys" :)

As to the "masterpiece" part, out of intellectual curiosity, I requested and received access to the MMBasic source code - I have zero intention of doing anything with it other than try to understand the internals a little better.

The various hardware implementations of the Maximite platform are very slick, but they are all essentially "transmission vectors" for MMBasic, which is the real masterpiece, especially the quantum leap in performance and capabilities the STM32H7 processor and expanded memory has enabled.

If you read my other post about the absurdity of rewriting code from scratch, MMBasic is the proof - it's been under continuous refinement and enhancement for nearly a decade... and it shows. Maximite Forever !
Enjoy Every Sandwich / Joe P.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 12:00am 08 Sep 2020
Copy link to clipboard 
Print this post

I read your linked piece about code rewriting but I think that highly depends on the quality of the source. From what I hear, Geoff Graham truly did create a masterpiece with MMBasic, writing source code so good that rewrites should indeed be unnecessary. On the other hand, I have on occasion inherited code that could only be dealt with by rewriting from scratch, partially due to underlying architecture change, partially due to, well, too many monkeys banging on keyboards. In contrast, Geoff has kept a firm hand in control of MMBasic, resulting in the quality we get to experience now.

Kudos and Thanks!
Visit Vegipete's *Mite Library for cool programs.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025