m2m模型翻译
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.

133 lines
5.1 KiB

6 months ago
  1. # -*- coding: utf-8 -*-
  2. #*****************************************************************************
  3. # Copyright (C) 2003-2006 Gary Bishop.
  4. # Copyright (C) 2006 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
  5. #
  6. # Distributed under the terms of the BSD License. The full license is in
  7. # the file COPYING, distributed as part of this software.
  8. #*****************************************************************************
  9. from __future__ import print_function, unicode_literals, absolute_import
  10. from . import winconstants as c32
  11. from pyreadline.logger import log
  12. from ctypes import windll
  13. import ctypes
  14. # table for translating virtual keys to X windows key symbols
  15. from .common import KeyPress
  16. code2sym_map = {c32.VK_CANCEL: 'cancel',
  17. c32.VK_BACK: 'backspace',
  18. c32.VK_TAB: 'tab',
  19. c32.VK_CLEAR: 'clear',
  20. c32.VK_RETURN: 'return',
  21. c32.VK_SHIFT: 'shift_l',
  22. c32.VK_CONTROL: 'control_l',
  23. c32.VK_MENU: 'alt_l',
  24. c32.VK_PAUSE: 'pause',
  25. c32.VK_CAPITAL: 'caps_lock',
  26. c32.VK_ESCAPE: 'escape',
  27. c32.VK_SPACE: 'space',
  28. c32.VK_PRIOR: 'prior',
  29. c32.VK_NEXT: 'next',
  30. c32.VK_END: 'end',
  31. c32.VK_HOME: 'home',
  32. c32.VK_LEFT: 'left',
  33. c32.VK_UP: 'up',
  34. c32.VK_RIGHT: 'right',
  35. c32.VK_DOWN: 'down',
  36. c32.VK_SELECT: 'select',
  37. c32.VK_PRINT: 'print',
  38. c32.VK_EXECUTE: 'execute',
  39. c32.VK_SNAPSHOT: 'snapshot',
  40. c32.VK_INSERT: 'insert',
  41. c32.VK_DELETE: 'delete',
  42. c32.VK_HELP: 'help',
  43. c32.VK_F1: 'f1',
  44. c32.VK_F2: 'f2',
  45. c32.VK_F3: 'f3',
  46. c32.VK_F4: 'f4',
  47. c32.VK_F5: 'f5',
  48. c32.VK_F6: 'f6',
  49. c32.VK_F7: 'f7',
  50. c32.VK_F8: 'f8',
  51. c32.VK_F9: 'f9',
  52. c32.VK_F10: 'f10',
  53. c32.VK_F11: 'f11',
  54. c32.VK_F12: 'f12',
  55. c32.VK_F13: 'f13',
  56. c32.VK_F14: 'f14',
  57. c32.VK_F15: 'f15',
  58. c32.VK_F16: 'f16',
  59. c32.VK_F17: 'f17',
  60. c32.VK_F18: 'f18',
  61. c32.VK_F19: 'f19',
  62. c32.VK_F20: 'f20',
  63. c32.VK_F21: 'f21',
  64. c32.VK_F22: 'f22',
  65. c32.VK_F23: 'f23',
  66. c32.VK_F24: 'f24',
  67. c32.VK_NUMLOCK: 'num_lock,',
  68. c32.VK_SCROLL: 'scroll_lock',
  69. c32.VK_APPS: 'vk_apps',
  70. c32.VK_PROCESSKEY: 'vk_processkey',
  71. c32.VK_ATTN: 'vk_attn',
  72. c32.VK_CRSEL: 'vk_crsel',
  73. c32.VK_EXSEL: 'vk_exsel',
  74. c32.VK_EREOF: 'vk_ereof',
  75. c32.VK_PLAY: 'vk_play',
  76. c32.VK_ZOOM: 'vk_zoom',
  77. c32.VK_NONAME: 'vk_noname',
  78. c32.VK_PA1: 'vk_pa1',
  79. c32.VK_OEM_CLEAR: 'vk_oem_clear',
  80. c32.VK_NUMPAD0: 'numpad0',
  81. c32.VK_NUMPAD1: 'numpad1',
  82. c32.VK_NUMPAD2: 'numpad2',
  83. c32.VK_NUMPAD3: 'numpad3',
  84. c32.VK_NUMPAD4: 'numpad4',
  85. c32.VK_NUMPAD5: 'numpad5',
  86. c32.VK_NUMPAD6: 'numpad6',
  87. c32.VK_NUMPAD7: 'numpad7',
  88. c32.VK_NUMPAD8: 'numpad8',
  89. c32.VK_NUMPAD9: 'numpad9',
  90. c32.VK_DIVIDE: 'divide',
  91. c32.VK_MULTIPLY: 'multiply',
  92. c32.VK_ADD: 'add',
  93. c32.VK_SUBTRACT: 'subtract',
  94. c32.VK_DECIMAL: 'vk_decimal'
  95. }
  96. VkKeyScan = windll.user32.VkKeyScanA
  97. def char_to_keyinfo(char, control=False, meta=False, shift=False):
  98. k=KeyPress()
  99. vk = VkKeyScan(ord(char))
  100. if vk & 0xffff == 0xffff:
  101. print('VkKeyScan("%s") = %x' % (char, vk))
  102. raise ValueError('bad key')
  103. if vk & 0x100:
  104. k.shift = True
  105. if vk & 0x200:
  106. k.control = True
  107. if vk & 0x400:
  108. k.meta = True
  109. k.char=chr(vk & 0xff)
  110. return k
  111. def make_KeyPress(char, state, keycode):
  112. control = (state & (4+8)) != 0
  113. meta = (state & (1+2)) != 0
  114. shift = (state & 0x10) != 0
  115. if control and not meta:#Matches ctrl- chords should pass keycode as char
  116. char = chr(keycode)
  117. elif control and meta: #Matches alt gr and should just pass on char
  118. control = False
  119. meta = False
  120. try:
  121. keyname=code2sym_map[keycode]
  122. except KeyError:
  123. keyname = ""
  124. out = KeyPress(char, shift, control, meta, keyname)
  125. return out
  126. if __name__ == "__main__":
  127. import startup