Feature request > IDE/Syntax

KEYPRESS() and KEYRELEASE()

(1/2) > >>

S. P. Gardebiter:
It would be nice to have KEYPRESS() and KEYRELEASE() commands.

And yeah, I know that you can do it yourself with code. ;)

Schranz0r:
*SIGN*!  :good:

Beginner:
I know this request is very old, but i think the problem is still present, right? I agree to the request that something like keypress() and keyrelease() would be very helpful. Or at least something like keyhit() and keydown()

Ian Price:
I've never really seen a need for either of these. Just use a keypress timer to prevent or allow multiple/timed keypresses.

eg

--- Code: (glbasic) ---// Prevent multiple key presses
IF KEY(XX) AND press=0
 blah blah
 press=10
ENDIF

IF press>0 then DEC PRESS

--- End code ---


--- Code: (glbasic) ---// Timed key
IF KEY(XX) THEN INC held

IF held>YY THEN dosomething.

--- End code ---

You could even roll them into your own functions.

Schranz0r:
My version.
Just take 10 min to make, hope there are no bugs...



--- Code: (glbasic) ---// --------------------------------- //
// Project: KeyEvents
// Start: Sunday, September 15, 2013
// IDE Version: 11.414


// SETCURRENTDIR("Media") // go to media files


TYPE TKey

keyID%
status% //nothing = 0, down = 1, released = -1

FUNCTION isDown:
IF self.status = 1
RETURN TRUE
ENDIF
ENDFUNCTION

FUNCTION isReleased:
IF self.status = -1
RETURN TRUE
ENDIF
ENDFUNCTION

ENDTYPE

GLOBAL KEYBOARD[] AS TKey

 
LOCAL count1, count2

InitKeyboard()

WHILE TRUE

IF KEYBOARD[57].isDown()
PRINT "SPACEBAR IS DOWN!",10,10
ENDIF

IF KEYBOARD[57].isReleased()
INC count1
ENDIF


PRINT "Spacebar Release-Count: "+count1, 10,20


IF KEYBOARD[28].isDown()
PRINT "ENTER IS DOWN!",10,50
ENDIF

IF KEYBOARD[28].isReleased()
INC count2
ENDIF


PRINT "ENTER Release-Count: "+count2, 10,60


ExamineKeyboard()
SHOWSCREEN
WEND
END


FUNCTION InitKeyboard:
FOR i = 0 TO 211

LOCAL k AS TKey
k.keyID = i
DIMPUSH KEYBOARD[], k
NEXT
ENDFUNCTION

FUNCTION ExamineKeyboard:

FOREACH k IN KEYBOARD[]
LOCAL _down = KEY(k.keyID)

IF k.status = 0 AND _down = FALSE THEN CONTINUE // nothing to do here! Next one pls! :D

IF k.status = 1 AND _down
CONTINUE //still active ( hold the key down ) I'm out,nothing to do here
ELSE
//OK, some work here
IF k.status = 0 AND _down = TRUE
k.status = 1
CONTINUE
ENDIF
IF k.status = 1 AND _down = FALSE
k.status = -1
CONTINUE
ENDIF

IF k.status = -1 AND _down = FALSE
k.status = 0
CONTINUE
ENDIF

ENDIF

NEXT

ENDFUNCTION
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version