Paul__B:
Well, for a start you have to use "Keyboard.begin" in setup.
Then try Keyboard.print(0xE0,0x32); for volume up,
and Keyboard.print(0xE0,0xF0,0x32); to cancel it.
Keyboard.print(0xE0,0x21); for volume down,
and Keyboard.print(0xE0,0xF0,0x21); to cancel it.
I know this thread's a bit old, but I found it helpful. I'm wondering if Keyboard.begin requires that it's in the setup. It seems like it'd be better to put it in the loop and only activate itself as a keyboard when sending a command. Otherwise in order to stop it, in order to re-program the Arduino, it would require a digital pin to send the Keyboard.end command.
I only just downloaded the software, at work, and my hardware's at home to test this.
Like this! I'm still working on what you did to those codes to expand them the way you did.
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
char VolUp = 0xE0,0x32;
char VolDn = 0xE0,0x21;
char Delet = 0x2E;
char Alt = 0x12;
char Ctrl = 0x11;
}
void loop() {
// Volume UP:
if(digitalRead(2)==LOW){
Keyboard.begin;
Keyboard.print(VolUp);
delay(50);
Keyboard.end;
delay(10);
}
// Volume Down:
if(digitalRead(3)==LOW{
Keyboard.begin;
Keyboard.print(VolDn)
delay(50);
Keyboard.end;
delay(10);
}
// EMERGENCY
if(digitalRead(4)==LOW{
Keyboard.begin;
Keyboard.press(Ctrl);
Keyboard.press(Alt);
Keyboard.press(Delet);
delay(100);
Keyboard.releaseAll();
delay(1000);
Keyboard.end;
delay(10);
}
I suppose the problem here is that the Arduino is likely to have to re-register as a keyboard everytime this is activated. So you'll hear the "DoDOO!" sound at the start of every loop, and the PC may not be quick enough to register the device and then get the input. I'm going to ignore my wife and kid this evening and try to get to this. I wish I had brought it with me to work. 