keybrd library is an open source library for creating custom-keyboard firmware.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

Code_AutoShift.h 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef CODE_AUTOSHIFT_H
  2. #define CODE_AUTOSHIFT_H
  3. #include "Code.h"
  4. #include "Code_Shift.h"
  5. /* Code_AutoShift is an abstract base class for Codes that depend on automatic shifting.
  6. Code_AutoShift can manage one or more shift keys.
  7. Example initialization:
  8. const Code_Shift s_shift(MODIFIERKEY_LEFT_SHIFT);
  9. const Code_Shift *const ptrsS[] = { &s_shift };
  10. const Code_Shift *const *const Code_AutoShift::ptrsShifts = ptrsS;
  11. const uint8_t Code_AutoShift::shiftCount = sizeof(ptrsShifts)/sizeof(*ptrsShifts);
  12. The two Code_Shift pointer arrays (ptrsShifts and ptrsS) must have distinct names.
  13. Automatic shifting is usful on multi-layered keyboards.
  14. The shift state for Code_ScS and Code_ScNS are changed and restored:
  15. Code_ScS object is a scancode shifted e.g. '%' in symbols layer
  16. Code_ScNS object is a scancode not shifted e.g. '5' in numbers layer
  17. keyboards without Code_ScS and Code_ScNS can omit ptrsShifts[] array and
  18. and place scancode MODIFIERKEY_LEFT_SHIFT directly in Code_Sc:
  19. Code_Sc s_shift(MODIFIERKEY_LEFT_SHIFT);
  20. */
  21. class Code_AutoShift : public Code
  22. {
  23. private:
  24. static Code_Shift *const *const ptrsShifts; //array of Code_Shift pointers
  25. static const uint8_t shiftCount;
  26. protected:
  27. bool isShifted() const;
  28. void releaseAllShifts() const;
  29. void restoreAllShifts() const;
  30. public:
  31. virtual void press()=0;
  32. virtual void release()=0;
  33. };
  34. #endif