keys.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. from __future__ import unicode_literals
  2. __all__ = (
  3. 'Key',
  4. 'Keys',
  5. )
  6. class Key(object):
  7. def __init__(self, name):
  8. #: Descriptive way of writing keys in configuration files. e.g. <C-A>
  9. #: for ``Control-A``.
  10. self.name = name
  11. def __repr__(self):
  12. return '%s(%r)' % (self.__class__.__name__, self.name)
  13. class Keys(object):
  14. Escape = Key('<Escape>')
  15. ControlA = Key('<C-A>')
  16. ControlB = Key('<C-B>')
  17. ControlC = Key('<C-C>')
  18. ControlD = Key('<C-D>')
  19. ControlE = Key('<C-E>')
  20. ControlF = Key('<C-F>')
  21. ControlG = Key('<C-G>')
  22. ControlH = Key('<C-H>')
  23. ControlI = Key('<C-I>') # Tab
  24. ControlJ = Key('<C-J>') # Enter
  25. ControlK = Key('<C-K>')
  26. ControlL = Key('<C-L>')
  27. ControlM = Key('<C-M>') # Enter
  28. ControlN = Key('<C-N>')
  29. ControlO = Key('<C-O>')
  30. ControlP = Key('<C-P>')
  31. ControlQ = Key('<C-Q>')
  32. ControlR = Key('<C-R>')
  33. ControlS = Key('<C-S>')
  34. ControlT = Key('<C-T>')
  35. ControlU = Key('<C-U>')
  36. ControlV = Key('<C-V>')
  37. ControlW = Key('<C-W>')
  38. ControlX = Key('<C-X>')
  39. ControlY = Key('<C-Y>')
  40. ControlZ = Key('<C-Z>')
  41. ControlSpace = Key('<C-Space>')
  42. ControlBackslash = Key('<C-Backslash>')
  43. ControlSquareClose = Key('<C-SquareClose>')
  44. ControlCircumflex = Key('<C-Circumflex>')
  45. ControlUnderscore = Key('<C-Underscore>')
  46. ControlLeft = Key('<C-Left>')
  47. ControlRight = Key('<C-Right>')
  48. ControlUp = Key('<C-Up>')
  49. ControlDown = Key('<C-Down>')
  50. Up = Key('<Up>')
  51. Down = Key('<Down>')
  52. Right = Key('<Right>')
  53. Left = Key('<Left>')
  54. ShiftLeft = Key('<ShiftLeft>')
  55. ShiftUp = Key('<ShiftUp>')
  56. ShiftDown = Key('<ShiftDown>')
  57. ShiftRight = Key('<ShiftRight>')
  58. Home = Key('<Home>')
  59. End = Key('<End>')
  60. Delete = Key('<Delete>')
  61. ShiftDelete = Key('<ShiftDelete>')
  62. ControlDelete = Key('<C-Delete>')
  63. PageUp = Key('<PageUp>')
  64. PageDown = Key('<PageDown>')
  65. BackTab = Key('<BackTab>') # shift + tab
  66. Insert = Key('<Insert>')
  67. Backspace = Key('<Backspace>')
  68. # Aliases.
  69. Tab = ControlI
  70. Enter = ControlJ
  71. # XXX: Actually Enter equals ControlM, not ControlJ,
  72. # However, in prompt_toolkit, we made the mistake of translating
  73. # \r into \n during the input, so everyone is now handling the
  74. # enter key by binding ControlJ.
  75. # From now on, it's better to bind `Keys.Enter` everywhere,
  76. # because that's future compatible, and will still work when we
  77. # stop replacing \r by \n.
  78. F1 = Key('<F1>')
  79. F2 = Key('<F2>')
  80. F3 = Key('<F3>')
  81. F4 = Key('<F4>')
  82. F5 = Key('<F5>')
  83. F6 = Key('<F6>')
  84. F7 = Key('<F7>')
  85. F8 = Key('<F8>')
  86. F9 = Key('<F9>')
  87. F10 = Key('<F10>')
  88. F11 = Key('<F11>')
  89. F12 = Key('<F12>')
  90. F13 = Key('<F13>')
  91. F14 = Key('<F14>')
  92. F15 = Key('<F15>')
  93. F16 = Key('<F16>')
  94. F17 = Key('<F17>')
  95. F18 = Key('<F18>')
  96. F19 = Key('<F19>')
  97. F20 = Key('<F20>')
  98. F21 = Key('<F21>')
  99. F22 = Key('<F22>')
  100. F23 = Key('<F23>')
  101. F24 = Key('<F24>')
  102. # Matches any key.
  103. Any = Key('<Any>')
  104. # Special
  105. CPRResponse = Key('<Cursor-Position-Response>')
  106. Vt100MouseEvent = Key('<Vt100-Mouse-Event>')
  107. WindowsMouseEvent = Key('<Windows-Mouse-Event>')
  108. BracketedPaste = Key('<Bracketed-Paste>')
  109. # Key which is ignored. (The key binding for this key should not do
  110. # anything.)
  111. Ignore = Key('<Ignore>')