@Chrisir
Your question gave me an idea to make a Varargs function, which is something I'we wanted to do but didn't have an idea for what it would do!
No one should use this function for keyboard shortcut's as @GoToLoop 's solution is simple, robust and has the wider support.
I don't know about anything that requires arbitrary key press combos other than fighting games, and this isn't good for that, as it's too crude and just written for practicing varargs. And most keyboards aren't good for it either.
void setup() {}
void draw() {
background(keycombo(70,71,72)?255:0); // white if F+G+H is pressed, otherwise black
}
/* keycombo(int... takes N number of keycodes and returns true if ALL of those are held, irrregardles of order pressed, or if other keys are held as well*/
boolean[] keysheld = new boolean[128]; /* not sure if 128 is the right number */
void keyPressed() { keysheld[keyCode]=true; /* println(keyCode); */}
void keyReleased(){ keysheld[keyCode]=false; }
boolean keycombo(int...k){
for (int i=0; i<k.length; i++)
{ if (!keysheld[k[i]]){ return false;} }
return true;
}
Answers
CTRL+Z is key
26
,032
or0x1A
.https://en.Wikipedia.org/wiki/Control-Z
doesn't work.
do you mean
ah, I got it - I have to use key
thanks, mate!
Thank you!
...and how can I read F1, F2, F3........ please?
Thank you!
You can copy, paste & run this sketch in Processing to find out all keyCode values by pressing them:
http://studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G
Or you can look up their corresponding constants in KeyEvent's class ref doc:
http://docs.Oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html#field.summary
For example, VK_F1 is
112
as keyCode: ;)Without using import:
when I just use keyCode == 112
It seems keyCode gives 2 values directly after another?
It works just fine when I hit F1 and other F keys when using the online sketch in the PDE.
Can you post your problematic sketch then? ~:>
@Chrisir -- re:F1 key etc., check out the thread:
Thanks everybody, I appreciate it
@Chrisir
Can you elaborate more?
@Chrisir Your question gave me an idea to make a Varargs function, which is something I'we wanted to do but didn't have an idea for what it would do!
No one should use this function for keyboard shortcut's as @GoToLoop 's solution is simple, robust and has the wider support.
I don't know about anything that requires arbitrary key press combos other than fighting games, and this isn't good for that, as it's too crude and just written for practicing varargs.
And most keyboards aren't good for it either.
Thanks!
This code works for me for F1
and this doesn't work because of P3D
it's a bug !!!! And I was thinking I was mixing things up a bit.
see also here https://github.com/processing/processing/issues/4654