I have been trying to use a remote to control my computer, using the mouse.h and the keyboard.h libraries. I can't seem to find what the term for the volume up and down buttons are on a mac, if any could shed some light that would be great!
Aren't they just F10, F11 and F12?
i.e.
KEY_F10 | 0xCB | 203 |
---|---|---|
KEY_F11 | 0xCC | 204 |
KEY_F12 | 0xCD | 205 |
1 Like
Please read:
Unfortunately, the Volume Up and Volume Down keys are outside the range that the Keyboard library can support.
const uint8_t Keyboard_Volume_Up_RAW = 0x80;
const uint8_t Keyboard_Volume_Down_RAW = 0x81;
You can add functions to the keyboard library to support raw key codes:
// pressRaw() adds the specified USB raw keycode to the persistent key
// report and sends the report.
size_t Keyboard_::pressRaw(uint8_t k)
{
uint8_t i;
// 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;
}
// releaseRaw() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
size_t Keyboard_::releaseRaw(uint8_t k)
{
uint8_t i;
// Test the key report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it shouldn't be)
for (i=0; i<6; i++) {
if (0 != k && _keyReport.keys[i] == k) {
_keyReport.keys[i] = 0x00;
}
}
sendReport(&_keyReport);
return 1;
}
size_t Keyboard_::writeRaw(uint8_t c)
{
uint8_t p = pressRaw(c); // Keydown
releaseRaw(c); // Keyup
return p; // just return the result of press() since releaseRaw() almost always returns 1
}
You would add these functions to Keyboard.cpp and modify the Keyboard class in Keyboard.h to add:
size_t writeRaw(uint8_t k);
size_t pressRaw(uint8_t k);
size_t releaseRaw(uint8_t k);
1 Like
Thanks so much for the help! Using f10, f11, f12 seems to work great! I am continually impressed by the willingness to help by everyone here!
Thanks again!
Haakon Olsen
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.