You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
8 years ago
|
/* -*- mode: c++ -*-
|
||
8 years ago
|
* Kaleidoscope-ShapeShifter -- Change the shifted symbols on any key of your choice
|
||
7 years ago
|
* Copyright (C) 2016, 2017 Keyboard.io, Inc
|
||
8 years ago
|
*
|
||
7 years ago
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
8 years ago
|
*
|
||
7 years ago
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
8 years ago
|
*
|
||
7 years ago
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
8 years ago
|
*/
|
||
|
|
||
8 years ago
|
#include <Kaleidoscope-ShapeShifter.h>
|
||
8 years ago
|
|
||
8 years ago
|
namespace kaleidoscope {
|
||
6 years ago
|
namespace plugin {
|
||
8 years ago
|
|
||
8 years ago
|
const ShapeShifter::dictionary_t *ShapeShifter::dictionary = NULL;
|
||
8 years ago
|
bool ShapeShifter::mod_active_;
|
||
8 years ago
|
|
||
7 years ago
|
EventHandlerResult ShapeShifter::beforeReportingState() {
|
||
5 years ago
|
mod_active_ = kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_LeftShift) ||
|
||
|
kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_RightShift);
|
||
7 years ago
|
return EventHandlerResult::OK;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
EventHandlerResult ShapeShifter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
|
||
8 years ago
|
if (!dictionary)
|
||
7 years ago
|
return EventHandlerResult::OK;
|
||
8 years ago
|
|
||
8 years ago
|
// If Shift is not active, bail out early.
|
||
8 years ago
|
if (!mod_active_)
|
||
7 years ago
|
return EventHandlerResult::OK;
|
||
8 years ago
|
|
||
8 years ago
|
Key orig, repl;
|
||
8 years ago
|
|
||
8 years ago
|
// Try to find the current key in the dictionary
|
||
|
uint8_t i = 0;
|
||
|
do {
|
||
5 years ago
|
orig = dictionary[i].original.readFromProgmem();
|
||
8 years ago
|
i++;
|
||
5 years ago
|
} while (orig != Key_NoKey &&
|
||
|
orig != mapped_key);
|
||
8 years ago
|
i--;
|
||
8 years ago
|
|
||
8 years ago
|
// If not found, bail out.
|
||
5 years ago
|
if (orig == Key_NoKey)
|
||
7 years ago
|
return EventHandlerResult::OK;
|
||
8 years ago
|
|
||
5 years ago
|
repl = dictionary[i].replacement.readFromProgmem();
|
||
8 years ago
|
|
||
8 years ago
|
// If found, handle the alternate key instead
|
||
7 years ago
|
mapped_key = repl;
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
6 years ago
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
kaleidoscope::plugin::ShapeShifter ShapeShifter;
|