Skip to content

Instantly share code, notes, and snippets.

@ragingcomputer
Created December 15, 2017 21:06
Show Gist options
  • Save ragingcomputer/0a808134f6fbe23b55b93abf7e2e3450 to your computer and use it in GitHub Desktop.
Save ragingcomputer/0a808134f6fbe23b55b93abf7e2e3450 to your computer and use it in GitHub Desktop.
#include <Keypad.h>
#include "Keyboard.h"
const byte ROWS = 2;
const byte COLS = 4;
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','4'},
{'5','6','7','8'}
};
byte rowPins[ROWS] = { 10, 16 };
byte colPins[COLS] = { 6, 7, 8, 9 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
}
void loop() {
char key = kpd.getKey();
if(key) // Check for a valid key.
{
Serial.println(key);
switch (key)
{
case '1':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F1);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '2':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F2);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '3':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F3);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '4':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F4);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '5':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F5);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '6':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F6);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '7':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F7);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
case '8':
Keyboard.begin();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F8);
delay(100);
Keyboard.releaseAll();
Keyboard.end();
break;
default:
Serial.println("Key Not Defined");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment