Help me (KeyUP)
Blitz3D Forums/Blitz3D Programming/Help me (KeyUP)
| ||
Hello, please someone help me, I need to create a code for an event is triggered only when the button this up, after being swamped. Well for example that pressing the escape key to exit the game can only happen when you release the key. I thought of a variable, and a truth function, but this does not work. I thank you in advance for help. |
| ||
Just arm a variable when the key is held and check to see if it's still armed after the button is released.Global trigger = 0 If KeyDown(trigger_key) = True trigger = 1 ;Arm the "trigger" End If If KeyDown(trigger_key) = False And trigger = 1 ;this code does whatever it's supposed to upon releasing the key ;DO CODE HERE ;trigger = 0 ;resets the trigger if it's repeatable End If |
| ||
Function KeyUP(Tecla,Estado) If KeyDown(Tecla) = True Estado = 1 ;Arm the "trigger" End If If KeyDown(Tecla) = False And Estado = 1 End Estado = 0 ;resets the trigger if it's repeatable End If End Function No working :(. Edit: Ok no problem. Function KeyUP(Tecla,Estado) If KeyDown(Tecla) = True Key_Escape = 1 End If If KeyDown(Tecla) = False And Key_Escape = 1 End Key_Escape = 0 End If End Function Bucle... KeyUp(Tecla,key_Escape) |
| ||
now I have a inconveniete, I need to put a goto command inside the function, is this possible??, and I've tried and it gives me error. |
| ||
Okay so I see what you are trying to do here, you need to use a bool setup on this... I would chose something like the select command.. But you could go straight If...Then, but I like the select option... http://www.blitzmax.com/b3ddocs/command.php?name=Select&ref=2d_a-z The trigger idea is okay, but then you run into a lot of variables that you just don't need for what you are trying to do... Thanks, WILLIAM MCCOLLOM AKA FBEPYON@... |
| ||
Unless I misunderstood Yue, that doesn't do what he was asking. The question was not to do something when the key is pressed, and do something else when it is not pressed. The question was how to do something one time when the key is released after having been pressed. The program almost has to have a trigger to keep track of if the specific key was hit, and when it's released. The trigger idea is okay, but then you run into a lot of variables that you just don't need for what you are trying to do... One global variable is not "a lot" of variables to keep track of. |
| ||
Well this is what I do to trigger things. You can still us Variables, but add it to the Keyhit(1)<>TRUE and set the variable there... it seems to work good for me.. |