• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""HID constant definitions.
6"""
7
8import usb_constants
9
10
11class DescriptorType(object):
12  """Class descriptors.
13
14  See Device Class Definition for Human Interface Devices (HID) Version 1.11
15  section 7.1.
16  """
17  HID = usb_constants.Type.CLASS | 0x01
18  REPORT = usb_constants.Type.CLASS | 0x02
19  PHYSICAL = usb_constants.Type.CLASS | 0x03
20
21
22class Scope(object):
23  """Item scope.
24
25  See Device Class Definition for Human Interface Devices (HID) Version 1.11
26  section 6.2.2.2.
27  """
28  MAIN = 0
29  GLOBAL = 1
30  LOCAL = 2
31
32
33class CollectionType(object):
34  """Collection types.
35
36  See Device Class Definition for Human Interface Devices (HID) Version 1.11
37  section 6.2.2.4.
38  """
39  PHYSICAL = 0
40  APPLICATION = 1
41  LOGICAL = 2
42  REPORT = 3
43  NAMED_ARRAY = 4
44  USAGE_SWITCH = 5
45  USAGE_MODIFIER = 6
46
47
48class Request(object):
49  """Class specific requests.
50
51  See Device Class Definition for Human Interface Devices (HID) Version 1.11
52  section 7.2.
53  """
54  GET_REPORT = 1
55  GET_IDLE = 2
56  GET_PROTOCOL = 3
57  SET_REPORT = 9
58  SET_IDLE = 0x0A
59  SET_PROTOCOL = 0x0B
60
61
62class ReportType(object):
63  """Report types.
64
65  See Device Class Definition for Human Interface Devices (HID) Version 1.11
66  section 7.2.1.
67  """
68  INPUT = 1
69  OUTPUT = 2
70  FEATURE = 3
71
72
73class ModifierKey(object):
74  """Keyboard modifier key report values.
75
76  See Device Class Definition for Human Interface Devices (HID) Version 1.11
77  section 8.3 and HID Usage Tables Version 1.1 Table 12.
78  """
79  L_CTRL = 0x01
80  L_SHIFT = 0x02
81  L_ALT = 0x04
82  L_GUI = 0x08
83  R_CTRL = 0x10
84  R_SHIFT = 0x20
85  R_ALT = 0x40
86  R_GUI = 0x80
87
88
89class LED(object):
90  """Keyboard LED report values.
91
92  See Device Class Definition for Human Interface Devices (HID) Version 1.11
93  section B.1 and HID Usage Tables Version 1.1 Table 13.
94  """
95  NUM_LOCK = 0x01
96  CAPS_LOCK = 0x02
97  SCROLL_LOCK = 0x04
98  COMPOSE = 0x08
99  KANA = 0x10
100
101
102class Mouse(object):
103  """Mouse button report values.
104
105  See Device Class Definition for Human Interface Devices (HID) Version 1.11
106  section B.2.
107  """
108  BUTTON_1 = 0x01
109  BUTTON_2 = 0x02
110  BUTTON_3 = 0x04
111
112
113KEY_CODES = {}
114for key, code in zip(xrange(ord('a'), ord('z') + 1), xrange(4, 30)):
115  KEY_CODES[chr(key)] = code
116for key, code in zip(xrange(ord('1'), ord('9') + 1), xrange(30, 39)):
117  KEY_CODES[chr(key)] = code
118for key, code in zip(['Enter', 'Esc', 'Backspace', 'Tab', ' '], xrange(40, 45)):
119  KEY_CODES[key] = code
120for key, code in zip('-=[]\\', xrange(45, 50)):
121  KEY_CODES[key] = code
122for key, code in zip(';\'`,./', xrange(51, 57)):
123  KEY_CODES[key] = code
124for key, code in zip(
125    ['CapsLock', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10',
126     'F11', 'F12', 'PrintScreen', 'ScrollLock', 'Pause', 'Insert', 'Home',
127     'PageUp', 'PageDown', 'Delete', 'End', 'PageDown', 'RightArrow',
128     'LeftArrow', 'DownArrow', 'UpArrow', 'NumLock'],
129    xrange(57, 84)):
130  KEY_CODES[key] = code
131
132SHIFT_KEY_CODES = {}
133for key, code in zip(xrange(ord('A'), ord('Z') + 1), xrange(4, 30)):
134  SHIFT_KEY_CODES[chr(key)] = code
135for key, code in zip('!@#$%^&*()', xrange(30, 40)):
136  SHIFT_KEY_CODES[key] = code
137for key, code in zip('_+{}|', xrange(45, 50)):
138  SHIFT_KEY_CODES[key] = code
139for key, code in zip(':"~<>?', xrange(51, 57)):
140  SHIFT_KEY_CODES[key] = code
141