You seem to want actions to run when a key is held down?
When the key is either pressed or held down. But not when released.
The function I posted in the opening thread does not work as intended (execute when press or held). A better way that I could have phrased the question is, How can I achieve this?
I tried a few things and managed to find a solution, so I'll share it here. The solution required me to set up 2 event catching triggers and 1 trigger action
Event 1: Key pressed (Up and down)
Event 2: Key released (Up and down)
Trigger action: Run secondary actions
I created a global integer 'DirectionVertical' that is 0 by default. When the up key is pressed, it increments DirectionVertical by 1, when down is pressed, it reduces it by 1. Vice-versa when keys are released. After the increment/decrement occurs, both of the events check to see if DirectionVertical is non-0 . If true, the trigger action is run.
The trigger action is configured to run while DirectionVertical is non-0, thus, it will iterate as long as either key is held down.
PS: I apologize for not posting more code to make my question clearer, as it is for a confidential project, thus I do not wish to openly reveal it.
The code above is an extract of a trigger that catches key press and release events for the up and down keys (4 events total)
gi_UIKeyCurrent: Global to track last key pressed.
The first if condition checks if 2 subsequent events originate from the same key, this is the equivalent of a press and release of either key to prevent the secondary trigger from running upon release.
This however is flawed as it fails when I press & hold UP, then press and hold DOWN. Because it creates a scenario where the secondary trigger is run when my key(s) are released.
Edit: By intent, the secondary trigger should only run when either of the keys are pressed or held, but not on release.
I've been staring at this for hours, but I can't think of a solution to prevent this from happening... anyone got any ideas?
I've tried booleans.. but I keep running into a deadlock and it creates a mess of if's and elses
@Kueken531: Go
Yeah pretty much. I'll keep note to drop you a PM should any further problems arise on confidential matters :P
@Vanished131: Go
You seem to want actions to run when a key is held down?
When the key is either pressed or held down. But not when released.
The function I posted in the opening thread does not work as intended (execute when press or held). A better way that I could have phrased the question is, How can I achieve this?
I tried a few things and managed to find a solution, so I'll share it here. The solution required me to set up 2 event catching triggers and 1 trigger action
I created a global integer 'DirectionVertical' that is 0 by default. When the up key is pressed, it increments DirectionVertical by 1, when down is pressed, it reduces it by 1. Vice-versa when keys are released. After the increment/decrement occurs, both of the events check to see if DirectionVertical is non-0 . If true, the trigger action is run.
The trigger action is configured to run while DirectionVertical is non-0, thus, it will iterate as long as either key is held down.
PS: I apologize for not posting more code to make my question clearer, as it is for a confidential project, thus I do not wish to openly reveal it.
@Kueken531: Go
Both, for the up and down keys. I'm catching press and release because I need to know when the key is being held down.
@Vanished131: Go
Do you happen to have a link to the documentation of that function? I could not find it.
The code above is an extract of a trigger that catches key press and release events for the up and down keys (4 events total)
The first if condition checks if 2 subsequent events originate from the same key, this is the equivalent of a press and release of either key to prevent the secondary trigger from running upon release.
This however is flawed as it fails when I press & hold UP, then press and hold DOWN. Because it creates a scenario where the secondary trigger is run when my key(s) are released.
Edit: By intent, the secondary trigger should only run when either of the keys are pressed or held, but not on release.
I've been staring at this for hours, but I can't think of a solution to prevent this from happening... anyone got any ideas?
I've tried booleans.. but I keep running into a deadlock and it creates a mess of if's and elses