It would be nice to have KEYPRESS() and KEYRELEASE() commands.
And yeah, I know that you can do it yourself with code. ;)
*SIGN*! :good:
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()
I've never really seen a need for either of these. Just use a keypress timer to prevent or allow multiple/timed keypresses.
eg
// Prevent multiple key presses
IF KEY(XX) AND press=0
blah blah
press=10
ENDIF
IF press>0 then DEC PRESS
// Timed key
IF KEY(XX) THEN INC held
IF held>YY THEN dosomething.
You could even roll them into your own functions.
My version.
Just take 10 min to make, hope there are no bugs...
// --------------------------------- //
// 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
thank you, I will check if this meets my requirements.
My Code
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
TSetup uses :
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;
}