Author Topic: KEYPRESS() and KEYRELEASE()  (Read 3625 times)

Offline S. P. Gardebiter

  • Mr. Polyvector
  • ***
  • Posts: 245
    • View Profile
    • Tile 44 Interactive
KEYPRESS() and KEYRELEASE()
« on: 2010-Mar-19 »
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! ~

Online Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4974
  • O Rly?
    • View Profile
Re: KEYPRESS() and KEYRELEASE()
« Reply #1 on: 2010-Mar-20 »
*SIGN*!  :good:
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Beginner

  • Mc. Print
  • *
  • Posts: 33
    • View Profile
Re: KEYPRESS() and KEYRELEASE()
« Reply #2 on: 2013-Sep-15 »
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()

« Last Edit: 2013-Sep-15 by Beginner »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4128
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: KEYPRESS() and KEYRELEASE()
« Reply #3 on: 2013-Sep-15 »
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.

Online Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4974
  • O Rly?
    • View Profile
Re: KEYPRESS() and KEYRELEASE()
« Reply #4 on: 2013-Sep-15 »
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
« Last Edit: 2013-Sep-15 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Beginner

  • Mc. Print
  • *
  • Posts: 33
    • View Profile
Re: KEYPRESS() and KEYRELEASE()
« Reply #5 on: 2013-Sep-21 »
thank you, I will check if this meets my requirements.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3338
  • Integrated Brain
    • View Profile
Re: KEYPRESS() and KEYRELEASE()
« Reply #6 on: 2013-Sep-21 »
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

  • Guest
Re: KEYPRESS() and KEYRELEASE()
« Reply #7 on: 2013-Sep-23 »
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;
                        }