Created
August 13, 2021 17:27
-
-
Save singhangadin/4a7beb0da5bcae2ca1ac3553d8b737bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AceButton.h> | |
#include <Keyboard.h> | |
#include <LinkedList.h> | |
using namespace ace_button; | |
typedef LinkedList<int> KeyCodes; | |
class Key: public IEventHandler { | |
private: | |
uint8_t pin; | |
KeyCodes clickKeys, longPressKeys; | |
public: | |
Key() { | |
clickKeys = KeyCodes(); | |
longPressKeys = KeyCodes(); | |
} | |
void setup(uint8_t lPin); | |
int ifasciiMapChar(char ch); | |
void setClickKeys(KeyCodes &keyCodes); | |
void setLongPressKeys(KeyCodes &keyCodes); | |
void handleEvent(AceButton* button, uint8_t eventType, uint8_t buttonState); | |
}; | |
void Key::setClickKeys(KeyCodes &keyCodes) { | |
clickKeys.clear(); | |
for (int i = 0; i < keyCodes.size(); i++) { | |
clickKeys.add(keyCodes.get(i)); | |
} | |
} | |
void Key::setLongPressKeys(KeyCodes &keyCodes) { | |
longPressKeys.clear(); | |
for (int i = 0; i < keyCodes.size(); i++) { | |
longPressKeys.add(keyCodes.get(i)); | |
} | |
} | |
void Key::handleEvent(AceButton* button, uint8_t eventType, uint8_t buttonState) { | |
switch (eventType) { | |
case AceButton::kEventClicked: { | |
for (int i = 0; i < clickKeys.size(); i++) { | |
Keyboard.press(clickKeys.get(i)); | |
} | |
Keyboard.releaseAll(); | |
break; | |
} | |
case AceButton::kEventLongPressed: { | |
for (int i = 0; i < longPressKeys.size(); i++) { | |
Keyboard.press(longPressKeys.get(i)); | |
} | |
Keyboard.releaseAll(); | |
break; | |
} | |
} | |
} | |
void Key::setup(uint8_t lPin) { | |
pin = lPin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment