KEYPRESS() and KEYRELEASE()

Previous topic - Next topic

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. ;)
~ Cave Story rules! ~

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Beginner

#2
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) Select

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

IF press>0 then DEC PRESS


Code (glbasic) Select

// Timed key
IF KEY(XX) THEN INC held

IF held>YY THEN dosomething.


You could even roll them into your own functions.

I came. I saw. I played.

Schranz0r

#4
My version.
Just take 10 min to make, hope there are no bugs...


Code (glbasic) Select
// --------------------------------- //
// 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
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Beginner

thank you, I will check if this meets my requirements.

mentalthink

My Code

Code (glbasic) Select

global RR=0

static lock_Pressed
if key(X) and RR=0 then lock_Pressed = true
if lock_Pressed=true
  do something
endif
if key(no X) and RR=0 then lock_Pressed=false

//Release
if key(Y)
I do something
endif


I think this have to works, else I burn in the Hells  =D =D =D

MrTAToad

TSetup uses :

Code (glbasic) Select
if (tempB1)
{
if (mouse[loop].state[LBUTTON]==false)
{
mouse[loop].state[LBUTTON]=true;
mouse[loop].hits[LBUTTON]++;
}
}
else
{
mouse[loop].state[LBUTTON]=false;
}

if (tempB2)
{
if (mouse[loop].state[RBUTTON]==false)
{
mouse[loop].state[RBUTTON]=true;
mouse[loop].hits[RBUTTON]++;
}
}
else
{
mouse[loop].state[RBUTTON]=false;
}