Based on the chart here-http://arduino.cc/en/Reference/KeyboardModifiers
I'm trying to pass the decimal values of modifier keys into a function then to Keyboard.press( )
Its not quite working though, Keyboard.press doesn't take these arguments as suggested I suspect.
though it does for write, which is understandable but I'm trying to create a function that makes key bindings that requires .press.
Here what I have so far, dice on specialKey(), no dice on combo()
The way I read the documentation, you need to use two Keyboard.write() calls to send the modifier key, then the to-be-modified key, NOT Keyboard.press().
everything works the way I would expect.
however, there is allot of repetitive behavior that uses those four lines, so I guess the real question is, how to do I make those four lines a function and be able to pass in the modifiers as arguments?
Looking a the serial documentation again I suppose it would still not help towards my end, even if it worked the same way. So I guess that particular effort was based on a poor assumption.
So I guess that particular effort was based on a poor assumption.
It was. The assumption that arguments to one function will work the same way with another function seems to be quite common, though. Even if I don't understand it.
if I did this in the main body of the code
everything works the way I would expect.
Then, why don't you do the same thing in the function?
The assumption that arguments to one function will work the same way with another function seems to be quite common, though. Even if I don't understand it.
I think folks like my self, not used to the world of programming are just way too used to implicit language vs explicit language. So they mistakenly apply implicit skills to an explicit problem like I did.
Then, why don't you do the same thing in the function?
combo(KEY_LEFT_SHIFT, KEY_LEFT_ALT);//<---not ints or chars
// but those are the arguments that I know to work
//it is suggested that these could be represented as 129 and 130
combo(129, 130);// does't function as expected ether
void combo(char key1, char key2)//<---I don't want to pass a string,
//--------------------------- and If that is the way to do it, I'm not sure how
{
Keyboard.press(key1);
Keyboard.press(key2);
delay(100);
Keyboard.releaseAll();
}
I just tried setting these as strings which would not be awful If I keep them in progmem but yet again I'm stumped on how to properly pass the data type to the function.
on my computer, pressing these two keys simultaneously would change the layout to qwerty
which is necessary for forthcoming Keyboard.print() statements to not look like gibberish
regardless that fine detail, I've also tried things like alt f2 (run promt) to no result (keys which are all the same with my layout)
on my computer, pressing these two keys simultaneously would change the layout to qwerty
which is necessary for forthcoming Keyboard.print() statements to not look like gibberish
That detail in particular in only necessary for odd balls like my self using a non-standard key layout, but its really more of the context of the issue then the issue its self.
The Keyboard class is defined in HID.cpp, where press() is defined as taking a uint8_t. So, that is what your function should use.
I'm really confused as to what is going on then, because looking at the source, I can see that Keyboard.write() uses press and press takes decimals... well.. maybe not for modifiers, guess I wouldn't have been able to test that with release right there.
for context
size_t Keyboard_::write(uint8_t c)
{
uint8_t p = press(c); // Keydown
uint8_t r = release(c); // Keyup
return (p); // just return the result of press() since release() almost always returns 1
}
So there must be something in press that forces modifiers to be taken as their keywords, in which case i'm out of luck. I just don't see it though... but I am little thick headed.. might be right there in the _keyReport.modifiers exception I just don't understand and I'm having a hard time finding where that object is.
size_t Keyboard_::press(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
} else if (k >= 128) { // it's a modifier key
_keyReport.modifiers |= (1<<(k-128));//<-------------------right here?
k = 0;
} else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
setWriteError();
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers |= 0x02; // the left shift modifier
k &= 0x7F;
}
}
// Add k to the key report only if it's not already present
// and if there is an empty slot.
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
_keyReport.keys[4] != k && _keyReport.keys[5] != k) {
for (i=0; i<6; i++) {
if (_keyReport.keys[i] == 0x00) {
_keyReport.keys[i] = k;
break;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
sendReport(&_keyReport);
return 1;
}
I got lost here. What do you mean by "and press takes decimals"? decimals is not a type. Or a meaningful description of a numeric value, either.
basically unsigned byte 1100001 goes through but unsigned byte 10000010 gets ignored and I am not really sure why because if the latter value didn't get ignored my program would work the way I expect it to.
basically unsigned byte 1100001 goes through but unsigned byte 10000010 gets ignored and I am not really sure why because if the latter value didn't get ignored my program would work the way I expect it to.
Goes through what? How do you know that it goes through whatever?
solution... embarrassingly enough the answer was pulled from my first sketch from a couple of weeks ago... real simple, assign the key definitions to chars. Why this works or why I did this to begin with and forgot, I couldn't tell you.
Possibly because char is a signed type, with a valid range of values from -128 to 127.
good point, i'm kinda all over all over the place in how I misuse and understand terminology. However tested with the byte data type the same results occur