![]() |
Forum Index : Microcontroller and PC projects : MM: Help with INKEY$
![]() ![]() |
|||||
Author | Message | ||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
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 KingdomPosts: 2944 |
@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 ![]() WW From the MaxiMite manual (v4.5) |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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 KingdomPosts: 2944 |
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: AustraliaPosts: 6283 |
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: AustraliaPosts: 3292 |
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 |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |