Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:15 27 Nov 2024 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 Bug

Author Message
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 12:42am 02 Mar 2013
Copy link to clipboard 
Print this post

Hi,

I made this program...V4.3

? "press a few keys, then press (i) for input"

Do

mykeydown=KeyDown

If mykeydown <> 0 Then GoSub branchout

Pause 100

Loop

branchout:

If mykeydown = 105 Then

Input "Why does it put in the keydown presses?";test$

? "you inputted ";test$
EndIf

Return


When executing I typed the alphabet "abcdefgh", then when I typed (i) it wanted my input, but the alphabet was already there with the (i). I typed good and the string it returned was "abcdefghigood"

Is this a bug....

Regards Dennis
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 12:54am 02 Mar 2013
Copy link to clipboard 
Print this post

Nick raised this as a possible bug when he wrote his latest game. The answer was that Keydown does not clear or take a character from the keyboard buffer. I think Geoff said this behaviour will be changed in V4.4 when released. If so then what is the difference between Keydown and Inkey$ ?
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 12:57am 02 Mar 2013
Copy link to clipboard 
Print this post

Hi,
I was using inkey$, but i thought this would be easier for my maxifont program and free up 254 bytes of memory from the resultant text$=inkey$

I should read the forums more often...

thanks . will have to change it back..

Regards Dennis
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:13am 02 Mar 2013
Copy link to clipboard 
Print this post

You could empty the keyboard buffer with inkey$ once you got your keydown value.
You do not need to store the inkey$ value because you already have the keydown value so you still save the bytes.


Microblocks. Build with logic.
 
Nick

Guru

Joined: 09/06/2011
Location: Australia
Posts: 512
Posted: 10:13am 02 Mar 2013
Copy link to clipboard 
Print this post

  BobD said   If so then what is the difference between Keydown and Inkey$ ?


INKEY$ has the added disadvantage of including key delay and the key repeat strobe which is not what you want when using the keyboard in a fast action game.

For example...

In my game, if I wanted to move the man character to the right, I would press the right arrow key.

INKEY$ would send that key's code and my man would move to the right 1 position.

But, INKEY then delays for a short time sending 0's even though the right arrow key is still being held down and I want the man character to continue moving.

The man instead stops since it's reading 0's. When the key delay is finished, it send the key's code again and the man continues walking.

But, now the key repeat kicks in! This sends a few 0's then the code then a few 0's again then the code... and this repeats for the duration of the key being pressed.

The overall effect is that the man doesn't move smoothly and responsively.

I can make my software ignore the 0' but that tended to create a lag and that reduced resposiveness also.

Hence the KEYDOWN command which is essentially like INKEY$ but doesn't throw out the 0's.

Nick
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 10:52am 02 Mar 2013
Copy link to clipboard 
Print this post

Thanks Nick
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 06:55pm 02 Mar 2013
Copy link to clipboard 
Print this post

Hi,

@ tzadvantage

  Quote  You could empty the keyboard buffer with inkey$ once you got your keydown value.
You do not need to store the inkey$ value because you already have the keydown value so you still save the bytes.


you mean like, just before my input command :

inkey$ : input " what I need for input";test$

regards dennis

Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:58pm 02 Mar 2013
Copy link to clipboard 
Print this post

@Dennis

You would need to use a while loop and repeat the inkey$ until the keyboard buffer is empty.

Another good spot is right after using the keydown function.
If you use the inkey$ once you know there was a keypress the inkey$ is fast and empties the keyboard buffer right away. Once the keydown function is fixed in the next version you can remove those inkey$.

mykeydown = keydown
if keydown <> 0 then
inkey$
gosub branchout
end if

Microblocks. Build with logic.
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 08:05pm 02 Mar 2013
Copy link to clipboard 
Print this post

@ TZAdvantage

Thanks I thought afterwards it would be better there, where you suggested..

Dennis
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
JonS
Newbie

Joined: 28/02/2013
Location: United Kingdom
Posts: 4
Posted: 11:26pm 02 Mar 2013
Copy link to clipboard 
Print this post

I need someone to validate this additional Inkey/Keydown bug as it could just be my keyboard.

Before 4.3 (possibly 4.2 also) Inkey$ would report additional values when the SHIFT key was held down in conjunction with the Cursor keys. So Right Cursor would give 131 and SHIFT+Right Cursor 163.

Since KEYDOWN, both Inkey$ and KEYDOWN no longer report the SHIFT+Cursor - it stays at the Cursor only vlaue.

But, as stated this could just be my keyboard (although unlikely as everything else functions Ok) - can someone confirm either way - and if at all possible suggest an alternative way to read both as I need the ability to do this for a Sprite Editor program i'm working on.

Many thanks for any help..


Jon Silvera (teamFUZE)
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 07:34pm 03 Mar 2013
Copy link to clipboard 
Print this post

  JonS said   I need someone to validate this additional Inkey/Keydown bug as it could just be my keyboard.

Before 4.3 (possibly 4.2 also) Inkey$ would report additional values when the SHIFT key was held down in conjunction with the Cursor keys. So Right Cursor would give 131 and SHIFT+Right Cursor 163.


Jon, Right Cursor and Shift Right Cursor return the same value on my keyboard too. It is the same with all the cursor keys inc Home, End, Page Up and Page Down, whether dedicated cursor keys or keys on the numeric keypad with Num Lock off.

Cheers,
Hugh
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 07:52pm 03 Mar 2013
Copy link to clipboard 
Print this post

  shoebuckle said  
  JonS said   I need someone to validate this additional Inkey/Keydown bug as it could just be my keyboard.

Before 4.3 (possibly 4.2 also) Inkey$ would report additional values when the SHIFT key was held down in conjunction with the Cursor keys. So Right Cursor would give 131 and SHIFT+Right Cursor 163.


Jon, Right Cursor and Shift Right Cursor return the same value on my keyboard too. It is the same with all the cursor keys inc Home, End, Page Up and Page Down, whether dedicated cursor keys or keys on the numeric keypad with Num Lock off.

Cheers,
Hugh


I have just gone back through a number of MMBasic versions with the same result back as far as v3.0 using

Do
? "Press a key"
Do
a$=Inkey$
Loop until a$<>""
? Asc(a$)
Loop


Looks to me like a bug if the shifted value is supposed to be different.
Cheers,
Hugh
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 07:59pm 03 Mar 2013
Copy link to clipboard 
Print this post

The shift function only works with the F1 to F12 keys. However the Control key should / may affect the other keys like left and right arrow. Refer to the V4.3 manual page 53, the first paragraph below the table.
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 09:15pm 03 Mar 2013
Copy link to clipboard 
Print this post

Hi,

SHift-Right cursor changes nothing , but ctrl-right cursor changes the value of keydown for me.

ctrl-any key changes most things

Keyboard ps/2 BTC Model E5XKB5199

Dennis

Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:41pm 03 Mar 2013
Copy link to clipboard 
Print this post

Yes, the shift modifier has never worked on the arrow keys.

The output from a PS2 keyboard is very hard to decode and getting the shift modifier to work correctly is still on my todo list.

Geoff
Geoff Graham - http://geoffg.net
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:17am 04 Mar 2013
Copy link to clipboard 
Print this post

  Geoff said  The output from a PS2 keyboard is very hard to decode and getting the shift modifier to work correctly is still on my todo list


Tell me about it!

I built a dual pic decoder (PS2 to I2C) that pretty closely replicates the PC keyboard with all keys as ascii value. It has a number of lookup tables e.g. Shift, control, Alt etc but not combinations of say ctrl-alt. It took up quite a bit of firmware space on a 16F88.

The first chip did the decoding and output as 8 bit parallel and the second chip did the i2c. It could hook up to the MM either in parallel or i2c if someone wanted something close to a "real" PS2.
David M.
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 12:42am 04 Mar 2013
Copy link to clipboard 
Print this post

Hi all,

@TZAdvantage
your code snippet suggestion won't work as inkey$ is not a standalone command.

mykeydown = keydown
if mykeydown <> 0 then
inkey$
gosub branchout
end if


so I changed it to...

do
mykeydown = keydown
if mykeydown <> 0 then
null=asc(inkey$)
'send keyboard buffer to bit bucket as number(4 bytes), not string (256 bytes)
gosub branchout
pause 100 ' whoa slow down, goes too fast
end if
loop

branchout:
'check which key pressed

return



Dennis
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
Print this page


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

© JAQ Software 2024