I have to simulate this mouse action. Instead of a mouse I can use the space button or with the jumps in front of the kinect. How can I control these actions over time or the frequency of repeating something at a certain time ? For example how many “zeros” has arrived the last two seconds or how many false or true have in last two seconds when hit the space bar…
Any ideas?
Thanks!
void mouseMoved()
{
int fx=mouseX-pmouseX, fy=mouseY-pmouseY;
if (max(abs(fx), abs(fy))>2) {
DO SOMETHING
}
}
Not entirely sure I understand… are you asking how you can record mouse movements or keypresses and replay them later?
There are different ways you can go about it; storing mouseX and mouseY in an array and writing that to disk so you can load it later? Or you can store keypresses with a hashmap, and document what time they were pressed etc.?
If, for example, the space key is pressed three times in the last two seconds, then start some action, if it’s not, then nothing. So I have to check the action constantly in real time, for a short past interval. I don’t need a mouse…If I store this values in a array, will it not overflow quickly?
If literally you’d like to define custom ‘key events’, like a triple pressing of the space bar in 2 seconds, or something, I’d indeed make an ArrayList or HashMap that you store the keypresses in, along with a timestamp. You iterate through that array, both counting the keypresses in it, and checking whether their timestamp is older than 2 seconds ago – and chucking them out if so. If it counts three valid keypresses, it fires your action.