Quick Help

Previous topic - Next topic

kamakazieturtle

Just curious, was wondering if there is a way to accept input only once when a key is pressed. To elaborate, I have a scenario such as: If KEY(?) Do "something". Now when I hold that key, i get: "something" "something" "something" "something" "something" "something." It continually does it, anyway to make it only do "something" when i press the key, then release and press again? Thanks in advance.  =D

Kitty Hello


kamakazieturtle

Thank you Kitty Hello, I will definitely be using this quite a bit. I'll be sure to mention you in credits if I ever finish a project.  :'( Lol, thanks again.

Hemlos

#3
I was just browsing around and noticed i have a code that solves the problem with one small function.
Gernots solution is wonderful for multiple languages...i dont know if this works for other languages or not.
Let me know how it does.

Code (glbasic) Select
// ------------------------------------------------------------- //
// ---  KeyBoardIO  --- detect any key press...
// returns instance of key pressed..one time...after button is released.
//  ...then returns that keycode. saves for alot of if's
// ------------------------------------------------------------- //
FUNCTION KeyBoardIO:
LOCAL i
STATIC INIT_KEYBOARD,K,SENDKWAIT,SKB
K=-1
FOR i=0 TO 299
IF KEY(i) THEN K=i
NEXT
IF (K=-1) AND (SENDKWAIT=TRUE); SENDKWAIT=FALSE; RETURN SKB; ENDIF
IF K>-1; SENDKWAIT=TRUE; SKB=K; K=-1; ENDIF
RETURN K
ENDFUNCTION


Keypressed=KeyboardIO()
If Keypressed=-1 then no keys have been pressed and released.
if key is pressed, then it returns one time the code. ie keypressed will be a number > -1
Bing ChatGpt is pretty smart :O