#include "Keyboard.h" const int rowNum = 6; const int colNum = 11; const int rowPin[rowNum] = { 14, 15, 18, 19, 20, 21 }; const int colPin[colNum] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const byte keyMap[rowNum][colNum] = { { 0xB2, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xB0 }, // BkSp, F1, F2, F3, F4, F5, F6, F7, F8, F9, Enter { 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x00 }, // 00, 1, 2, 3, 4, 5, 6, 7, 8, 9, 00 (00 = Nul) { 0x00, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x00 }, // 00, q, w, e, r, t, y, u, i, o, 00 { 0x00, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x00 }, // 00, a, s, d, f, g, h, j, k, l, 00 { 0x00, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x00 }, // 00, z, x, c, v, b, n, m, comma, dot, 00 { 0xDA, 0xDA, 0x00, 0xD9, 0xD9, 0x00, 0xDA, 0xDA, 0x00, 0xD9, 0xD9 } // Up, Up, 00, Down, Down, 00, Up, Up, 00, Down, Down }; bool currentState[rowNum][colNum]; bool beforeState[rowNum][colNum]; int i,j; void setup() { for( i = 0; i < rowNum; i++){ pinMode(rowPin[i],OUTPUT); } for( i = 0; i < colNum; i++){ pinMode(colPin[i],INPUT_PULLUP); } for( i = 0; i < rowNum; i++){ for( j = 0; j < colNum; j++){ currentState[i][j] = HIGH; beforeState[i][j] = HIGH; } digitalWrite(rowPin[i],HIGH); } Serial.begin(9600); Keyboard.begin(); } void loop() { for( i = 0; i < rowNum; i++){ digitalWrite( rowPin[i], LOW ); for( j = 0; j < colNum; j++){ currentState[i][j] = digitalRead(colPin[j]); if ( currentState[i][j] != beforeState[i][j] ){ Serial.print("key("); Serial.print(i); Serial.print(","); Serial.print(j); Serial.print(")"); if ( currentState[i][j] == LOW){ Serial.println(" Push!"); Keyboard.press( keyMap[i][j] ); } else { Serial.println(" Release!"); Keyboard.release( keyMap[i][j] ); } beforeState[i][j] = currentState[i][j]; } } digitalWrite( rowPin[i], HIGH ); } delay(3); }