mod.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package input
  2. // KeyMod represents modifier keys.
  3. type KeyMod uint16
  4. // Modifier keys.
  5. const (
  6. ModShift KeyMod = 1 << iota
  7. ModAlt
  8. ModCtrl
  9. ModMeta
  10. // These modifiers are used with the Kitty protocol.
  11. // XXX: Meta and Super are swapped in the Kitty protocol,
  12. // this is to preserve compatibility with XTerm modifiers.
  13. ModHyper
  14. ModSuper // Windows/Command keys
  15. // These are key lock states.
  16. ModCapsLock
  17. ModNumLock
  18. ModScrollLock // Defined in Windows API only
  19. )
  20. // HasShift reports whether the Shift modifier is set.
  21. func (m KeyMod) HasShift() bool {
  22. return m&ModShift != 0
  23. }
  24. // HasAlt reports whether the Alt modifier is set.
  25. func (m KeyMod) HasAlt() bool {
  26. return m&ModAlt != 0
  27. }
  28. // HasCtrl reports whether the Ctrl modifier is set.
  29. func (m KeyMod) HasCtrl() bool {
  30. return m&ModCtrl != 0
  31. }
  32. // HasMeta reports whether the Meta modifier is set.
  33. func (m KeyMod) HasMeta() bool {
  34. return m&ModMeta != 0
  35. }
  36. // HasHyper reports whether the Hyper modifier is set.
  37. func (m KeyMod) HasHyper() bool {
  38. return m&ModHyper != 0
  39. }
  40. // HasSuper reports whether the Super modifier is set.
  41. func (m KeyMod) HasSuper() bool {
  42. return m&ModSuper != 0
  43. }
  44. // HasCapsLock reports whether the CapsLock key is enabled.
  45. func (m KeyMod) HasCapsLock() bool {
  46. return m&ModCapsLock != 0
  47. }
  48. // HasNumLock reports whether the NumLock key is enabled.
  49. func (m KeyMod) HasNumLock() bool {
  50. return m&ModNumLock != 0
  51. }
  52. // HasScrollLock reports whether the ScrollLock key is enabled.
  53. func (m KeyMod) HasScrollLock() bool {
  54. return m&ModScrollLock != 0
  55. }