altlocal_keys.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2018-2022 Eric Gebhart <e.a.gebhart@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // Create custom keycodes with arbitrary shifted and unshifted keys.
  15. // originally for dvorak on bepo. But used by beakl on qwerty now too.
  16. // Why?: Because the keycodes are actually defined on the computer. So
  17. // if you are trying to have dvorak, or beakl on bepo-fr, the shifted keys
  18. // are wrong. But, I want my dvorak, so this allows the pairing of keys into
  19. // a keycode that has shifted and non shifted behavior, outside of what the
  20. // locale map says on the computer.
  21. //
  22. // These are the keys for dvorak on bepo. column one is the keycode and mods for
  23. // the unshifted key, the second column is the keycode and mods for the shifted key.
  24. // GR is Good Range. It subtracts SAFE_RANGE from the keycode so we can make a
  25. // reasonably sized array without difficulties. The macro is for the constant declarations
  26. // the function is for when we use it.
  27. //make an alt_local_keys.def - see the example.
  28. // Include this file where you have your process_record_user function,
  29. // call process_alt_local_key inside your process_record_user.
  30. #include USERSPACE_H
  31. #include "altlocal_keys.h"
  32. const uint16_t key_translations[][2][2] = {
  33. #include "altlocal_keys.def"
  34. };
  35. uint8_t gr(uint16_t kc){
  36. return (kc - SAFE_RANGE);
  37. }
  38. // send the right keycode for the right mod.
  39. // remove the mods we are taking care of,
  40. // send our keycodes then restore them.
  41. // all so we can make dvorak keys from bepo keycodes.
  42. void send_keycode(uint16_t kc){
  43. uint8_t tmp_mods = get_mods();
  44. bool is_shifted = ( tmp_mods & (MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)) );
  45. // need to turn of the shift if it is on.
  46. unregister_mods((MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)));
  47. if(is_shifted){
  48. register_mods(SHIFTED_MODS(kc));
  49. register_code16(SHIFTED_KEY(kc));
  50. unregister_code16(SHIFTED_KEY(kc));
  51. unregister_mods(SHIFTED_MODS(kc));
  52. } else{
  53. register_mods(UNSHIFTED_MODS(kc));
  54. register_code16(UNSHIFTED_KEY(kc));
  55. unregister_code16(UNSHIFTED_KEY(kc));
  56. unregister_mods(UNSHIFTED_MODS(kc));
  57. }
  58. clear_mods();
  59. register_mods(tmp_mods);
  60. }
  61. bool process_alt_local_key(uint16_t keycode, keyrecord_t* record) {
  62. switch(keycode){
  63. case ALT_LOCAL_KEYS_START ... ALT_LOCAL_KEYS_END:
  64. if(record->event.pressed)
  65. send_keycode(keycode);
  66. unregister_code(keycode);
  67. break;
  68. }
  69. return (true);
  70. }