|
|
@ -21,158 +21,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
|
|
|
|
|
|
|
//Default, empty constructor
|
|
|
|
//Default, empty constructor
|
|
|
|
ModifierKeyMap::ModifierKeyMap(){
|
|
|
|
ModifierKeyMap::ModifierKeyMap() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Constructor with input and output, and assume default timeout
|
|
|
|
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_){
|
|
|
|
|
|
|
|
input = input_;
|
|
|
|
|
|
|
|
output = output_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Constructor with all three set
|
|
|
|
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
|
|
|
|
|
|
|
|
input = input_;
|
|
|
|
|
|
|
|
output = output_;
|
|
|
|
|
|
|
|
timeout = timeout_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Space Cadet
|
|
|
|
|
|
|
|
uint8_t SpaceCadet::map_size_ = 0;
|
|
|
|
|
|
|
|
ModifierKeyMap * SpaceCadet::map_;
|
|
|
|
|
|
|
|
uint16_t SpaceCadet::time_out = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Empty constructor
|
|
|
|
|
|
|
|
SpaceCadet::SpaceCadet() {
|
|
|
|
|
|
|
|
//By default, we make one with left shift sending left paren, and right shift sending right paren
|
|
|
|
|
|
|
|
static ModifierKeyMap internalMap[] = {
|
|
|
|
|
|
|
|
//By default, respect the default timeout
|
|
|
|
|
|
|
|
{Key_LeftShift, Key_LeftParen, 0}
|
|
|
|
|
|
|
|
,{Key_RightShift, Key_RightParen, 0}
|
|
|
|
|
|
|
|
//These may be uncommented, added, or set in the main sketch
|
|
|
|
|
|
|
|
/*,{Key_LeftGui,Key_LeftCurlyBracket,250}
|
|
|
|
|
|
|
|
,{Key_RightAlt,Key_RightCurlyBracket,250}
|
|
|
|
|
|
|
|
,{Key_LeftControl,Key_LeftBracket,250}
|
|
|
|
|
|
|
|
,{Key_RightControl,Key_RightBracket,250}*/
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Set the variables to our internal map
|
|
|
|
|
|
|
|
map_ = internalMap;
|
|
|
|
|
|
|
|
map_size_ = sizeof(internalMap)/sizeof(internalMap[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Void function to reset the modifier map if desired.
|
|
|
|
|
|
|
|
void SpaceCadet::setMap(ModifierKeyMap * map, uint8_t map_size){
|
|
|
|
|
|
|
|
//Set the map
|
|
|
|
|
|
|
|
map_ = map;
|
|
|
|
|
|
|
|
//set the map size to be the length of the array
|
|
|
|
|
|
|
|
map_size_ = map_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SpaceCadet::begin() {
|
|
|
|
|
|
|
|
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If nothing happened, bail out fast.
|
|
|
|
|
|
|
|
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
|
|
|
|
if (keyToggledOn(key_state)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(map_size_ > 0) {
|
|
|
|
|
|
|
|
//This will only set one key, and if it isn't in our map it clears everything
|
|
|
|
|
|
|
|
//for the non-pressed key
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
|
|
|
|
if(mapped_key.raw == map_[i].input.raw) {
|
|
|
|
|
|
|
|
//The keypress was valid and a match.
|
|
|
|
|
|
|
|
map_[i].flagged = true;
|
|
|
|
|
|
|
|
map_[i].start_time = millis();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//The keypress wasn't a match.
|
|
|
|
|
|
|
|
map_[i].flagged = false;
|
|
|
|
|
|
|
|
map_[i].start_time = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is all we need to do on keypress, let the next handler do its thing too.
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the state is empty, that means that either the shifts weren't pressed,
|
|
|
|
|
|
|
|
// or we used another key in the interim. in both cases, nothing special to do.
|
|
|
|
|
|
|
|
bool valid_key = false;
|
|
|
|
|
|
|
|
bool pressed_key_was_valid = false;
|
|
|
|
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(map_size_ > 0) {
|
|
|
|
|
|
|
|
//Look to see if any keys in our map are flagged
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (map_[i].flagged) {
|
|
|
|
|
|
|
|
valid_key = true;
|
|
|
|
|
|
|
|
index = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map_[i].input.raw == mapped_key.raw) {
|
|
|
|
|
|
|
|
pressed_key_was_valid = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If no valid mapped keys were pressed, simply return the keycode
|
|
|
|
//Constructor with input and output, and assume default timeout
|
|
|
|
if (!valid_key) {
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_) {
|
|
|
|
return mapped_key;
|
|
|
|
input = input_;
|
|
|
|
}
|
|
|
|
output = output_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//use the map index to find the local timeout for this key
|
|
|
|
//Constructor with all three set
|
|
|
|
uint16_t current_timeout = map_[index].timeout;
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
|
|
|
|
//If that isn't set, use the global timeout setting.
|
|
|
|
input = input_;
|
|
|
|
if(current_timeout == 0){
|
|
|
|
output = output_;
|
|
|
|
current_timeout = time_out;
|
|
|
|
timeout = timeout_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((millis() - map_[index].start_time) >= current_timeout) {
|
|
|
|
//Space Cadet
|
|
|
|
// if we timed out, that means we need to keep pressing the mapped
|
|
|
|
uint8_t SpaceCadet::map_size_ = 0;
|
|
|
|
// key, but we won't need to send the alternative key in the end
|
|
|
|
ModifierKeyMap * SpaceCadet::map_;
|
|
|
|
map_[index].flagged = false;
|
|
|
|
uint16_t SpaceCadet::time_out = 1000;
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
//Empty constructor
|
|
|
|
}
|
|
|
|
SpaceCadet::SpaceCadet() {
|
|
|
|
|
|
|
|
//By default, we make one with left shift sending left paren, and right shift sending right paren
|
|
|
|
|
|
|
|
static ModifierKeyMap internalMap[] = {
|
|
|
|
|
|
|
|
//By default, respect the default timeout
|
|
|
|
|
|
|
|
{Key_LeftShift, Key_LeftParen, 0}
|
|
|
|
|
|
|
|
, {Key_RightShift, Key_RightParen, 0}
|
|
|
|
|
|
|
|
//These may be uncommented, added, or set in the main sketch
|
|
|
|
|
|
|
|
/*,{Key_LeftGui,Key_LeftCurlyBracket,250}
|
|
|
|
|
|
|
|
,{Key_RightAlt,Key_RightCurlyBracket,250}
|
|
|
|
|
|
|
|
,{Key_LeftControl,Key_LeftBracket,250}
|
|
|
|
|
|
|
|
,{Key_RightControl,Key_RightBracket,250}*/
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Set the variables to our internal map
|
|
|
|
|
|
|
|
map_ = internalMap;
|
|
|
|
|
|
|
|
map_size_ = sizeof(internalMap) / sizeof(internalMap[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the key that was pressed isn't one of our mapped keys, just
|
|
|
|
//Void function to reset the modifier map if desired.
|
|
|
|
// return. This can happen when another key is released, and that should not
|
|
|
|
void SpaceCadet::setMap(ModifierKeyMap * map, uint8_t map_size) {
|
|
|
|
// interrupt us.
|
|
|
|
//Set the map
|
|
|
|
|
|
|
|
map_ = map;
|
|
|
|
|
|
|
|
//set the map size to be the length of the array
|
|
|
|
|
|
|
|
map_size_ = map_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!pressed_key_was_valid) {
|
|
|
|
void SpaceCadet::begin() {
|
|
|
|
return mapped_key;
|
|
|
|
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if a key toggled off (and that must be one of the mapped keys at this point),
|
|
|
|
Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
// send the alternative key instead (if we were interrupted, we bailed out earlier).
|
|
|
|
|
|
|
|
if (keyToggledOff(key_state)) {
|
|
|
|
// If nothing happened, bail out fast.
|
|
|
|
Key pressed_key = map_[index].input;
|
|
|
|
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
|
|
|
|
Key alternate_key = map_[index].output;
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
//Since we are sending the actual key (no need for shift, etc),
|
|
|
|
|
|
|
|
//only need to send that key and not the original key. In fact, we
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
//may want to even UNSET the originally pressed key (future
|
|
|
|
if (keyToggledOn(key_state)) {
|
|
|
|
//enhanacement?). This might also mean we don't need to return the
|
|
|
|
|
|
|
|
//key that was pressed, though I haven't confirmed that.
|
|
|
|
if (map_size_ > 0) {
|
|
|
|
handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
|
|
|
|
//This will only set one key, and if it isn't in our map it clears everything
|
|
|
|
hid::sendKeyboardReport();
|
|
|
|
//for the non-pressed key
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
//Unflag the key so we don't try this again.
|
|
|
|
if (mapped_key.raw == map_[i].input.raw) {
|
|
|
|
map_[index].flagged = false;
|
|
|
|
//The keypress was valid and a match.
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
map_[i].flagged = true;
|
|
|
|
|
|
|
|
map_[i].start_time = millis();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//The keypress wasn't a match.
|
|
|
|
|
|
|
|
map_[i].flagged = false;
|
|
|
|
|
|
|
|
map_[i].start_time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
// this is all we need to do on keypress, let the next handler do its thing too.
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the state is empty, that means that either the shifts weren't pressed,
|
|
|
|
|
|
|
|
// or we used another key in the interim. in both cases, nothing special to do.
|
|
|
|
|
|
|
|
bool valid_key = false;
|
|
|
|
|
|
|
|
bool pressed_key_was_valid = false;
|
|
|
|
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (map_size_ > 0) {
|
|
|
|
|
|
|
|
//Look to see if any keys in our map are flagged
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (map_[i].flagged) {
|
|
|
|
|
|
|
|
valid_key = true;
|
|
|
|
|
|
|
|
index = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map_[i].input.raw == mapped_key.raw) {
|
|
|
|
|
|
|
|
pressed_key_was_valid = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If no valid mapped keys were pressed, simply return the keycode
|
|
|
|
|
|
|
|
if (!valid_key) {
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//use the map index to find the local timeout for this key
|
|
|
|
|
|
|
|
uint16_t current_timeout = map_[index].timeout;
|
|
|
|
|
|
|
|
//If that isn't set, use the global timeout setting.
|
|
|
|
|
|
|
|
if (current_timeout == 0) {
|
|
|
|
|
|
|
|
current_timeout = time_out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((millis() - map_[index].start_time) >= current_timeout) {
|
|
|
|
|
|
|
|
// if we timed out, that means we need to keep pressing the mapped
|
|
|
|
|
|
|
|
// key, but we won't need to send the alternative key in the end
|
|
|
|
|
|
|
|
map_[index].flagged = false;
|
|
|
|
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the key that was pressed isn't one of our mapped keys, just
|
|
|
|
|
|
|
|
// return. This can happen when another key is released, and that should not
|
|
|
|
|
|
|
|
// interrupt us.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!pressed_key_was_valid) {
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if a key toggled off (and that must be one of the mapped keys at this point),
|
|
|
|
|
|
|
|
// send the alternative key instead (if we were interrupted, we bailed out earlier).
|
|
|
|
|
|
|
|
if (keyToggledOff(key_state)) {
|
|
|
|
|
|
|
|
Key pressed_key = map_[index].input;
|
|
|
|
|
|
|
|
Key alternate_key = map_[index].output;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Since we are sending the actual key (no need for shift, etc),
|
|
|
|
|
|
|
|
//only need to send that key and not the original key. In fact, we
|
|
|
|
|
|
|
|
//may want to even UNSET the originally pressed key (future
|
|
|
|
|
|
|
|
//enhanacement?). This might also mean we don't need to return the
|
|
|
|
|
|
|
|
//key that was pressed, though I haven't confirmed that.
|
|
|
|
|
|
|
|
handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
|
|
|
|
|
|
|
|
hid::sendKeyboardReport();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Unflag the key so we don't try this again.
|
|
|
|
|
|
|
|
map_[index].flagged = false;
|
|
|
|
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|