Go Down

Topic: Keyboard key codes (Read 2095 times) previous topic - next topic

cowasaki

I have been using my DUEGUI library and I want to create a flexible touch screen display with menus etc which then send relevant codes via USB keyboard control to the computer.  I can easily send ASCII codes and standard keys but I want to send "KEYPAD 1", "KEYPAD ENTER", "KEYPAD ." etc 

Is there a list of keyboard key codes.

cowasaki

Ok I've found out for myself so I'll share it with you lot :D

Here goes.....

Open the USBAPI.h file located at Java/hardware/arduino/sam/cores/arduino/USB/....

Look through the list and you will find the following section:

Code: [Select]
//===============================
//===================================
// Keyboard

#define KEY_LEFT_CTRL 0x80
#define KEY_LEFT_SHIFT 0x81
#define KEY_LEFT_ALT 0x82
#define KEY_LEFT_GUI 0x83
#define KEY_RIGHT_CTRL 0x84
#define KEY_RIGHT_SHIFT 0x85
#define KEY_RIGHT_ALT 0x86
#define KEY_RIGHT_GUI 0x87

#define KEY_UP_ARROW 0xDA
#define KEY_DOWN_ARROW 0xD9
#define KEY_LEFT_ARROW 0xD8
#define KEY_RIGHT_ARROW 0xD7
#define KEY_BACKSPACE 0xB2
#define KEY_TAB 0xB3
#define KEY_RETURN 0xB0
#define KEY_ESC 0xB1
#define KEY_INSERT 0xD1
#define KEY_DELETE 0xD4
#define KEY_PAGE_UP 0xD3
#define KEY_PAGE_DOWN 0xD6
#define KEY_HOME 0xD2
#define KEY_END 0xD5
#define KEY_CAPS_LOCK 0xC1
#define KEY_F1 0xC2
#define KEY_F2 0xC3
#define KEY_F3 0xC4
#define KEY_F4 0xC5
#define KEY_F5 0xC6
#define KEY_F6 0xC7
#define KEY_F7 0xC8
#define KEY_F8 0xC9
#define KEY_F9 0xCA
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD


You can now add your own which you can add from this list as follows:

Code: [Select]


// missing function keys
//
#define KEY_F13 0x68
#define KEY_F14 0x69
#define KEY_F15 0x6A
#define KEY_F16 0x6B
#define KEY_F17 0x6C
#define KEY_F18 0x6D
#define KEY_F19 0x6E
#define KEY_F20 0x6F
#define KEY_F21 0x70
#define KEY_F22 0x71
#define KEY_F23 0x72
#define KEY_F24 0x73
#define KEY_F24 0x73

// missing sound control keys
//
#define KEY_MUTE 0x7F
#define KEY_VOLUMEUP 0x80
#define KEY_VOLUMEDOWN 0x81

// Numeric keypad
//
#define KEY_KEYPAD_0 0x62
#define KEY_KEYPAD_1 0x59
#define KEY_KEYPAD_2 0x5A
#define KEY_KEYPAD_3 0x5B
#define KEY_KEYPAD_4 0x5C
#define KEY_KEYPAD_5 0x5D
#define KEY_KEYPAD_6 0x5E
#define KEY_KEYPAD_7 0x5F
#define KEY_KEYPAD_8 0x60
#define KEY_KEYPAD_9 0x61
#define KEY_KEYPAD_DECIMAL 0x63
#define KEY_KEYPAD_ENTER 0x58
#define KEY_KEYPAD_PLUS 0x57
#define KEY_KEYPAD_MINUS 0x56
#define KEY_KEYPAD_MULTIPLY 0x55
#define KEY_KEYPAD_DIVIDE 0x54
#define KEY_KEYPAD_NUMLOCK 0x53
#define KEY_KEYPAD_EQUALS 0x67




Will update further but the volume ones are a nice simple way of controlling the computers volume!

cowasaki

Oh well it didn't work in the end :(

Dilushan123

My arduino board show this erro i install keyboard.h liabary but seethis erro
Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\DHILUS~1\AppData\Local\Temp\arduino_modified_sketch_384137\sketch_may09b.ino: In function 'void setup()':

sketch_may09b:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.begin();

 ^

C:\Users\DHILUS~1\AppData\Local\Temp\arduino_modified_sketch_384137\sketch_may09b.ino: In function 'void loop()':

sketch_may09b:21: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("q");

 ^

sketch_may09b:26: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("w");

 ^

sketch_may09b:30: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("e");

 ^

sketch_may09b:34: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("r");

 ^

sketch_may09b:39: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("t");

 ^

sketch_may09b:44: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.print("y");

 ^

Multiple libraries were found for "Keyboard.h"
 Used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\libraries\Keyboard
 Not used: C:\Users\dhilushan\Documents\Arduino\libraries\Keyboard-1.0.1
exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


THe code

#include "Keyboard.h"

void setup() {
// put your setup code here, to run once:
Keyboard.begin();

}

void loop() {
// put your main code here, to run repeatedly:

int c = analogRead(A0);
int d = analogRead(A1);
int e = analogRead(A2);
int f = analogRead(A3);
int g = analogRead(A4);
int h = analogRead(A5);


if(c>800){
Keyboard.print("q");
delay(05);

}
if(d>800){
Keyboard.print("w");
delay(05);
}
if(e>800){
Keyboard.print("e");
delay(05);
}
if(f>800){
Keyboard.print("r");
delay(05);
}

if(g>800){
Keyboard.print("t");
delay(05);
}

if(h>800){
Keyboard.print("y");
delay(05);
}



}

Go Up