Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:13 02 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 : MM: Help with INKEY$

     Page 2 of 2    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 06:22am 25 Sep 2015
Copy link to clipboard 
Print this post

Hi Rob,

Many thanks for your ideas.

To be clear, the keys I require to be 'tested' in my looping program are on a PS2 keyboard which is connected directly to a MM+ via the MM+'s PS2 input pins.

Also connected to the MM+ is a SSD1963 LCD panel; and the whole setup is being used as a 'standalone' system (i.e. no computer connected)

I am not wanting or needing to create a 'dedicated' hardware keypad. Just simply need to test if certain keys are pressed at various points in my continually looping program. The thing is, many keys could be randomly 'bashed' during the looping program, but all of these 'presses' need to be ignored. Ideally I want to have a line (or two) of code saying effectively 'if key x is being pressed NOW, then goto label 'xyz'.

I do not need any interrupts (i.e. the key is not dictating the program flow instantly when the key is pressed).

Hope this all makes sense. It really seems like it should be very simple but is proving to be 'impossible'. Been working on this for too many hours; perhaps I need a break . . . .

WW




 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 06:34am 25 Sep 2015
Copy link to clipboard 
Print this post

@Geoff,

How easy is it to implement a KEYDOWN command into the MM+'s firmware? If I remember correctly, I believe it was included within MaxiMite's MMBasic??

I am not wanting to draw you away from the fact that the MM+ is primarily an embedded controller. It is just an enquiry to see if this is an easy five minute job for you, OR a major 'ball-ache' task that needs thinking about due to potentially many 'knock-on' effects.

If it is easy then can I offer you dinner (and dark ale) at 'our pub' in Chiswick for the next time you are over (assuming you implement KEYDOWN into MMBasic of course!)

WW

From the MaxiMite manual (v4.5)

  Quote  KEYDOWN FUNCTION
They KEYDOWN function makes it easy to tell if the user is holding down a key on the PS2 keyboard (like an arrow key). While the key is held down KEYDOWN will return the numeric value of the key, when no key is held down the function will return zero.
The KEYDOWN function will also remove any characters in the keyboard input buffer but, when playing a game, the user often still has their finger on a key when the game ends. For that reason the program should include the following line which will wait for the user to release the key and clear the buffer:
DO WHILE KEYDOWN AND INKEY$ <> "" : LOOP
Edited by WhiteWizzard 2015-09-26
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:55am 25 Sep 2015
Copy link to clipboard 
Print this post

I think it can be done with the ON KEY target.
What you would need is a 'TimeStamp' so that you can determine how long ago the key was pressed.
You can tweak the 500ms to shorter times to get closer to 'realtime'
[code]
ON KEY ReadKey
Dim LastKey$
Dim LastKeyTime


'main loop
DO
'Erase keys that are older then 500ms
IF LastKey$ <> "" AND Timer - LastKeyTime > 500 THEN
LastKey$ = ""
ENDIF

'If LastKey$ <> "" here then it is max 500ms ago that it was pressed

'Do your thing....


LOOP



SUB ReadKey()
LOCAL key$
DO
Key$ = INKEY$
if Key$ = "" EXIT DO
LastKey$ = Key$
LastKeyTime = Timer
LOOP
END SUB
[/code]

Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 07:02am 25 Sep 2015
Copy link to clipboard 
Print this post

Hi MB,

Yes - this is getting nearer to what I need

ON KEY seems to be a good way forward (highlighted by TassyJim yesterday). I think with the Timer you suggest then it may be a 'second-best' solution to KEYDOWN.

Thanks, I will have a play over the next couple of hours . . .

WW
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:22pm 25 Sep 2015
Copy link to clipboard 
Print this post

Another variation.
The ON KEY sub records any valid key presses.
The main loop checks the buffer$ and processes the key presses that are recorded.

This keeps the interrupt routine short as it should be.


' TassyJim
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM buffer$ ' global variable containing any valid keypresses

ON KEY grab

DO

IF buffer$<>"" THEN
'process keystrokes
keyval=asc(buffer$)
print keyval
buffer$=MID$(buffer$,2) ' discard after processing
ENDIF
PAUSE 200

LOOP

SUB grab
LOCAL k$
k$=INKEY$
IF INSTR("abcdABCD",k$)>0 THEN ' it is a valid key
buffer$=buffer$+k$
ENDIF
END SUB


Jim
VK7JH
MMedit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 02:02pm 25 Sep 2015
Copy link to clipboard 
Print this post

Unfortunately KEYDOWN is not a simple function to implement, it needed hooks in the PS2 processing code and was very untidy. Which (in part) was why I did not implement on the Micromite.

It would be much better if your need could be implemented some other way. Without testing it I believe that it could be best done using ON KEY to collect the characters in a buffer where you could then process them as you needed.

Geoff
Geoff Graham - http://geoffg.net
 
     Page 2 of 2    
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