multiple keys

is there a way to detect multiple keys being pressed on the keyboard? for example pressing up and left.

Comments

simultaneous keystrokes

Hi,

In practice two keys are not pressed at exactly the same time, but you can detect when two keys are pressed at almost the same, i.e. when the interval between them is say less than 1/10th of a second. Here is a simple program that does this:

DIM k(10)
let elapse=time
For n=1 to 10
GET KEY k(n)
let diff=time-elapse
IF diff<0.1 then ! simultaneous keystrokes
PRINT k(n-1),k(n)
ELSE
PRINT k(n) ! single keystrokes
END IF
let elapse=time
next n
END

Any help?

Big John

yes, it is helpful. however

yes, it is helpful.

however the problem with it (just from looking at the code) is that while you test for that, you dont know constantly what keys are being pressed. Maybe use "if key input" and take out the restriction on time?

but if you did that, the problem would be in, for example, 2d movement. say that the player is pressing up and left, to move forward and left, what if they are holding the buttons? it would move them the first direction pressed, but then it would keep going the second one pressed until they let go of the button.

could there be a way to know all of the keys pressed in that situation?

multiple keystrokes

Hi,

You are correct. If you keep your finger on the keys you only get the last key pressed not both keys. TB doesn't have a way of recording multiple keystrokes continuously. Even TC_event cannot help, even though it forms a queue of events, it still only records the last key pressed.
I would suggest you change the way your game works so that it uses mouse clicks or mouse dragging instead of keystrokes.

Regards
Big John

darn

ok i am not actually making, anything that would require this at the moment, but i have run into this in the past