As Megalomaniak said, last_key_event
is initialized as null
outside of the for loop, and is set at the end of the for loop.
I’ll do my best to try and explain how the code in the for loop works in regards to last_key_event
, which hopefully will help show how it’s working:
Inside the for loop it first checks to see if last_key_event
Is null
. Initially last_key_event
will be null
, since that is its initial value, and no combo checking will happen. Then last_key_event
will be set to the event being processed right before moving on to the next event in the combo_events
list (that is what last_key_event = event
is doing).
This makes it when the second event is being processed, last_key_event
is no longer null
, but rather is holding the event prior to the second event. Then the combo checking code will run since last_key_event
is no longer null
. input_key_event
is only null
for the first initial run through the for loop, and then after that it is always the previous event in combo_events
after the initial run.
The reason I wrote the example code like that was because I needed to compare two events in combo_events
. There are other, probably better, ways you could do get two or more items in a list, but that was the first way that came to mind when I was writing the example. :smile: