Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MC-10 Keyboard Arduino for Teensy 2.0
- // Ray Dios Haque - ray@oddree.com - 10/2012
- #include "Keypad.h"
- const byte ROWS = 7; //seven rows
- const byte COLS = 8; //eight columns
- char keys[ROWS][COLS] = {
- /* 1 2 3 4 5 6 7 8 */
- {'@','a','b','c','d','e','f','g'}, // ROW 1
- {'h','i','j','k','l','m','n','o'}, // ROW 2
- {'p','q','r','s','t','u','v','w'}, // ROW 3
- {'x','y','z','NO_KEY','NO_KEY','NO_KEY','KEY_ENTER',' '}, // ROW 4
- {'0','1','2','3','4','5','6','7'}, // ROW 5
- {'8','9',':',';',',','-','.','/'}, // ROW 6
- {'KEY_CONTROL','NO_KEY','KEY_BACKSPACE','NO_KEY','NO_KEY','NO_KEY','NO_KEY','KEY_RIGHTSHIFT'} // ROW 7
- };
- byte rowPins[ROWS] = {14, 15, 17, 18, 19, 20, 21}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {0, 1, 2, 3, 4, 5, 6, 7}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- boolean shiftkey = false; // Assuming from the get-go that SHIFT is not pressed!
- boolean controlkey = false; // Assuming from the get-go that the Control Key is not pressed!
- void setup(){
- //Serial.begin(9600);
- }
- void loop(){
- char key = keypad.getKey();
- if (key != NO_KEY){
- if (controlkey == true) {
- switch (key) {
- // F1 - F12 keys
- case'1': Keyboard.set_key1(KEY_F1); Keyboard.send_now(); break;
- case'2': Keyboard.set_key1(KEY_F2); Keyboard.send_now(); break;
- case'3': Keyboard.set_key1(KEY_F3); Keyboard.send_now(); break;
- case'4': Keyboard.set_key1(KEY_F4); Keyboard.send_now(); break;
- case'5': Keyboard.set_key1(KEY_F5); Keyboard.send_now(); break;
- case'6': Keyboard.set_key1(KEY_F6); Keyboard.send_now(); break;
- case'7': Keyboard.set_key1(KEY_F7); Keyboard.send_now(); break;
- case'8': Keyboard.set_key1(KEY_F8); Keyboard.send_now(); break;
- case'9': Keyboard.set_key1(KEY_F9); Keyboard.send_now(); break;
- case'0': Keyboard.set_key1(KEY_F10); Keyboard.send_now(); break;
- case':': Keyboard.set_key1(KEY_F11); Keyboard.send_now(); break;
- case'_': Keyboard.set_key1(KEY_F12); Keyboard.send_now(); break;
- // Arrow keys
- case'w': Keyboard.set_key1(KEY_UP); Keyboard.send_now(); break;
- case'z': Keyboard.set_key1(KEY_DOWN); Keyboard.send_now(); break;
- case'a': Keyboard.set_key1(KEY_LEFT); Keyboard.send_now(); break;
- case's': Keyboard.set_key1(KEY_RIGHT); Keyboard.send_now(); break;
- // Need a TAB key, of course
- case'KEY_ENTER': Keyboard.set_key1(KEY_TAB); Keyboard.send_now(); break;
- // Control Backspace (break key) = DELETE
- case'KEY_BACKSPACE': Keyboard.set_key1(KEY_DELETE); Keyboard.send_now(); break;
- // Control twice = ESC
- case'KEY_CONTROL': Keyboard.set_key1(KEY_ESC); Keyboard.send_now(); break;
- }
- Keyboard.set_key1(0); Keyboard.send_now(); // Reset to no keys being pressed
- controlkey = false; // Now leaving control key routine - so we reset the control.
- }
- else if (shiftkey == true) {
- switch (key) {
- // We pressed the shift key, so this is a CAP or uppper
- case '1': Keyboard.print('!'); break;
- case '2': Keyboard.print('"'); break;
- case '3': Keyboard.print('#'); break;
- case '4': Keyboard.print('$'); break;
- case '5': Keyboard.print('%'); break;
- case '6': Keyboard.print('&'); break;
- case '7': Keyboard.print('\''); break; // Note the backslash to escape the single quote!
- case '8': Keyboard.print('('); break;
- case '9': Keyboard.print(')'); break;
- case ':': Keyboard.print('*'); break;
- case '-': Keyboard.print('='); break;
- case ';': Keyboard.print('+'); break;
- case ',': Keyboard.print('<'); break;
- case '.': Keyboard.print('>'); break;
- case '/': Keyboard.print('?'); break;
- case 'a': Keyboard.print('A'); break;
- case 'b': Keyboard.print('B'); break;
- case 'c': Keyboard.print('C'); break;
- case 'd': Keyboard.print('D'); break;
- case 'e': Keyboard.print('E'); break;
- case 'f': Keyboard.print('F'); break;
- case 'g': Keyboard.print('G'); break;
- case 'h': Keyboard.print('H'); break;
- case 'i': Keyboard.print('I'); break;
- case 'j': Keyboard.print('J'); break;
- case 'k': Keyboard.print('K'); break;
- case 'l': Keyboard.print('L'); break;
- case 'm': Keyboard.print('M'); break;
- case 'n': Keyboard.print('N'); break;
- case 'o': Keyboard.print('O'); break;
- case 'p': Keyboard.print('P'); break;
- case 'q': Keyboard.print('Q'); break;
- case 'r': Keyboard.print('R'); break;
- case 's': Keyboard.print('S'); break;
- case 't': Keyboard.print('T'); break;
- case 'u': Keyboard.print('U'); break;
- case 'v': Keyboard.print('V'); break;
- case 'w': Keyboard.print('W'); break;
- case 'x': Keyboard.print('X'); break;
- case 'y': Keyboard.print('Y'); break;
- case 'z': Keyboard.print('Z'); break;
- case 'KEY_RIGHTSHIFT':
- // Tap SHIFT twice to CTRL+ALT+DELETE
- Keyboard.set_modifier(MODIFIERKEY_CTRL);
- Keyboard.send_now();
- Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
- Keyboard.send_now();
- Keyboard.set_key1(KEY_DELETE);
- Keyboard.send_now();
- Keyboard.set_modifier(0);
- Keyboard.set_key1(0);
- Keyboard.send_now();
- break;
- }
- shiftkey = false; // Now leaving shift key routine - so we reset the shift.
- }
- // Normal key presses
- else {
- switch (key) {
- case 'KEY_BACKSPACE':
- Keyboard.set_key1(KEY_BACKSPACE);
- Keyboard.send_now();
- Keyboard.set_key1(0);
- Keyboard.send_now();
- break;
- case 'KEY_ENTER':
- Keyboard.set_key1(KEY_ENTER);
- Keyboard.send_now();
- Keyboard.set_key1(0);
- Keyboard.send_now();
- break;
- case 'KEY_CONTROL':
- controlkey = true; // Next key will be a CONTROL key
- break;
- case 'KEY_RIGHTSHIFT':
- shiftkey = true; // Next key will be a CAP KEY or upper key
- break;
- default:
- //Serial.println(key);
- Keyboard.print(key);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement