Macro Keypad

From Norwich Hackspace
Revision as of 15:52, 16 March 2021 by Ben Norcutt (talk | contribs)
Jump to navigation Jump to search

What is it?
A macro keypad is physical or touch screen keypad that maps multiple or common used shortcut keys to an individual action, think (un)mute on Zoom which by default is ALT + A

Prior Art https://github.com/leobrowning92/numpad-ProMicro - This was the plan for V1.00 https://there.oughta.be/a/macro-keyboard https://handsontek.net/experience-building-free-touch-deck/

Implementation
There are multiple ways this can be done and a common approach is to use a Pro Micro as it has the ability to be programmed as a HID device and emulate both keyboard and mouse however I struggled to do this so ended using an ESP32 and presenting it as a bluetooth keyboard.

V1.00 - Status abandoned couldn't get Pro Micro to program
Pro micro - generic clone 3D Printed case - link from thingiverse goes here Cherry MX clone switches - ebay link here

V1.01 - Status working ESP32-WROOM Module - "borrowed" from HS 3D Printed case - https://www.thingiverse.com/thing:1735671/files Cherry MX clone switches - ebay link here

Currently have 2 switched hooked up to ESP32 sending ALT + a to mute and unmute and ALT + v to start and stop video

Uses the blekeyboard library for Arduino from https://github.com/T-vK/ESP32-BLE-Keyboard/

#define UK_KEYBOARD 1

#include <Arduino.h>
#include <BleKeyboard.h>
BleKeyboard bleKeyboard;


// Change the below values if desired
#define BUTTON_1_PIN 23
#define BUTTON_2_PIN 22
#define MESSAGE "Hello from ESP32\n"
#define DEVICE_NAME "My Keyboard"


// Forward declarations
void bluetoothTask(void*);
void typeText(const char* text);


bool isBleConnected = false;


void setup() {
    Serial.begin(115200);
    bleKeyboard.begin();
    // configure pin for button
    pinMode(BUTTON_1_PIN, INPUT_PULLUP);
    pinMode(BUTTON_2_PIN, INPUT_PULLUP);
}


void loop() {  
    if (bleKeyboard.isConnected() && digitalRead(BUTTON_1_PIN) == LOW) {
        // button has been pressed: type message
        //Serial.println(MESSAGE);
        //typeText(MESSAGE);
        Serial.println("Sending Ctrl+Alt+Shift...");
        bleKeyboard.press(KEY_LEFT_CTRL);
        bleKeyboard.press(KEY_LEFT_ALT);
        bleKeyboard.press(KEY_LEFT_SHIFT);
        delay(100);
        bleKeyboard.releaseAll();
        Serial.println("Sending F3...");
        //bleKeyboard.press(KEY_F3);
        bleKeyboard.press(KEY_LEFT_ALT);
        bleKeyboard.press('a');
        delay(100);
        bleKeyboard.releaseAll();       
             }
if (bleKeyboard.isConnected() && digitalRead(BUTTON_2_PIN) == LOW) {
        // button has been pressed: type message
        //Serial.println(MESSAGE);
        //typeText(MESSAGE);
        Serial.println("Sending Ctrl+Alt+Shift...");
        bleKeyboard.press(KEY_LEFT_CTRL);
        bleKeyboard.press(KEY_LEFT_ALT);
        bleKeyboard.press(KEY_LEFT_SHIFT);
        delay(100);
        bleKeyboard.releaseAll();
        Serial.println("Sending F3...");
        //bleKeyboard.press(KEY_F3);
        bleKeyboard.press(KEY_LEFT_ALT);
        bleKeyboard.press('v');
        delay(100);
        bleKeyboard.releaseAll();       
             }
}