2012-07-31 23:48:31 +02:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* key functions : special : code
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
|
|
|
* Released under The MIT License (MIT) (see "license.md")
|
|
|
|
* Project located at <https://github.com/benblazak/ergodox-firmware>
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2012-08-07 00:57:23 +02:00
|
|
|
#include "../../../lib-other/pjrc/usb_keyboard/usb_keyboard.h"
|
|
|
|
#include "../../../lib/usb/usage-page/keyboard.h"
|
2016-06-11 21:24:42 +02:00
|
|
|
#include "../../../keyboard/layout.h"
|
2012-08-07 00:57:23 +02:00
|
|
|
#include "../../../main.h"
|
2012-07-31 23:48:31 +02:00
|
|
|
#include "../public.h"
|
|
|
|
#include "../private.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-12-05 01:11:01 +01:00
|
|
|
/*
|
2016-02-04 12:16:53 +01:00
|
|
|
* Generate a 'shift' press or release before the normal keypress or release
|
2012-12-05 01:11:01 +01:00
|
|
|
*/
|
|
|
|
void kbfun_shift_press_release(void) {
|
2016-02-04 12:16:53 +01:00
|
|
|
_kbfun_press_release(main_arg_is_pressed, KEY_LeftShift);
|
|
|
|
kbfun_press_release();
|
2012-12-05 01:11:01 +01:00
|
|
|
}
|
|
|
|
|
2015-12-09 11:20:56 +01:00
|
|
|
/*
|
2016-02-04 12:16:53 +01:00
|
|
|
* Generate a 'control' press or release before the normal keypress or release
|
2015-12-09 11:20:56 +01:00
|
|
|
*/
|
|
|
|
void kbfun_control_press_release(void) {
|
2016-02-04 12:16:53 +01:00
|
|
|
_kbfun_press_release(main_arg_is_pressed, KEY_LeftControl);
|
|
|
|
kbfun_press_release();
|
2015-12-09 11:20:56 +01:00
|
|
|
}
|
|
|
|
|
2012-07-31 23:48:31 +02:00
|
|
|
/*
|
2016-02-04 12:16:53 +01:00
|
|
|
* When assigned to two keys (e.g. the physical left and right shift keys)
|
|
|
|
* (in both the press and release matrices), pressing and holding down one of
|
|
|
|
* the keys will make the second key toggle capslock
|
2012-07-31 23:48:31 +02:00
|
|
|
*
|
2016-02-04 12:16:53 +01:00
|
|
|
* If either of the shifts are pressed when the second key is pressed, they
|
|
|
|
* wil be released so that capslock will register properly when pressed.
|
|
|
|
* Capslock will then be pressed and released, and the original state of the
|
|
|
|
* shifts will be restored
|
2012-07-31 23:48:31 +02:00
|
|
|
*/
|
2012-08-07 00:57:23 +02:00
|
|
|
void kbfun_2_keys_capslock_press_release(void) {
|
2016-02-04 12:16:53 +01:00
|
|
|
static uint8_t keys_pressed;
|
|
|
|
static bool lshift_pressed;
|
|
|
|
static bool rshift_pressed;
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
uint8_t keycode = _kbfun_get_keycode();
|
2012-08-07 00:57:23 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
if (!main_arg_is_pressed) { keys_pressed--; }
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
// take care of the key that was actually pressed
|
|
|
|
_kbfun_press_release(main_arg_is_pressed, keycode);
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
// take care of capslock (only on the press of the 2nd key)
|
|
|
|
if (keys_pressed == 1 && main_arg_is_pressed) {
|
|
|
|
// save the state of left and right shift
|
|
|
|
lshift_pressed = _kbfun_is_pressed(KEY_LeftShift);
|
|
|
|
rshift_pressed = _kbfun_is_pressed(KEY_RightShift);
|
|
|
|
// disable both
|
|
|
|
_kbfun_press_release(false, KEY_LeftShift);
|
|
|
|
_kbfun_press_release(false, KEY_RightShift);
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
// press capslock, then release it
|
|
|
|
_kbfun_press_release(true, KEY_CapsLock); usb_keyboard_send();
|
|
|
|
_kbfun_press_release(false, KEY_CapsLock); usb_keyboard_send();
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
// restore the state of left and right shift
|
|
|
|
if (lshift_pressed) { _kbfun_press_release(true, KEY_LeftShift); }
|
|
|
|
if (rshift_pressed) { _kbfun_press_release(true, KEY_RightShift); }
|
|
|
|
}
|
2012-07-31 23:48:31 +02:00
|
|
|
|
2016-02-04 12:16:53 +01:00
|
|
|
if (main_arg_is_pressed) { keys_pressed++; }
|
2012-11-30 21:06:41 +01:00
|
|
|
}
|
|
|
|
|
2013-04-14 09:29:47 +02:00
|
|
|
/*
|
2016-02-04 12:16:53 +01:00
|
|
|
* Generate a keypress for a media key
|
2013-04-14 09:29:47 +02:00
|
|
|
*/
|
|
|
|
void kbfun_mediakey_press_release(void) {
|
2016-02-04 12:16:53 +01:00
|
|
|
uint8_t keycode = _kbfun_get_keycode();
|
|
|
|
_kbfun_mediakey_press_release(main_arg_is_pressed, keycode);
|
2013-04-14 09:29:47 +02:00
|
|
|
}
|
|
|
|
|
2012-11-30 21:06:41 +01:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* ------------------------------------------------------------------------- */
|