hidg0 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/hidg0.rb +211 -0
  5. metadata +71 -0
  6. metadata.gz.sig +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 68962cffd1ff46b36521423ed4632ead086fc8f6bfdfecdece33783ed79d9a4d
4
+ data.tar.gz: 5814ab247ff6cb222c62d6fa4a48b6c6c6d12696422e7024d0e616e31387989b
5
+ SHA512:
6
+ metadata.gz: e85e81a2cf5b98c1098d679b02d89bc24d2c64b76751cf514ab54d6fe2d00985888e7af3abf7311a153b31efe8be2c04b587f8c2238909771c4fa53457497781
7
+ data.tar.gz: f67fd1abb38793a45131237198f99354c723d08643b1e91172b9c772c92b6cd728ffc32964539703e7fb4fd13f0d41bc18adfb659d7a4994cebad1fed3c40319
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/hidg0.rb ADDED
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: hidg0.rb
4
+
5
+ # description: Used with a Raspberry PI Zero plugged into a computer to act as USB Keyboard (HID)
6
+
7
+ # This gem was made possible thanks to the code from [Turn Your Raspberry Pi Zero into a USB Keyboard (HID)](https://randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/)
8
+
9
+ # The following USB HID keyboard IDs were obtained from https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2#file-usb_hid_keys-h-L36-L76
10
+
11
+
12
+ NULL_CHAR = 0.chr
13
+
14
+ KEYS = {
15
+ none: 0, # No key pressed
16
+ err_ovf: 1, # Keyboard Error Roll Over - used for all slots if too many keys are pressed ("Phantom key")
17
+ a: 4, # Keyboard a and A
18
+ b: 5, # Keyboard b and B
19
+ c: 6, # Keyboard c and C
20
+ d: 7, # Keyboard d and D
21
+ e: 8, # Keyboard e and E
22
+ f: 9, # Keyboard f and F
23
+ g: 10, # Keyboard g and G
24
+ h: 11, # Keyboard h and H
25
+ i: 12, # Keyboard i and I
26
+ j: 13, # Keyboard j and J
27
+ k: 14, # Keyboard k and K
28
+ l: 15, # Keyboard l and L
29
+ m: 16, # Keyboard m and M
30
+ n: 17, # Keyboard n and N
31
+ o: 18, # Keyboard o and O
32
+ p: 19, # Keyboard p and P
33
+ q: 20, # Keyboard q and Q
34
+ r: 21, # Keyboard r and R
35
+ s: 22, # Keyboard s and S
36
+ t: 23, # Keyboard t and T
37
+ u: 24, # Keyboard u and U
38
+ v: 25, # Keyboard v and V
39
+ w: 26, # Keyboard w and W
40
+ x: 27, # Keyboard x and X
41
+ y: 28, # Keyboard y and Y
42
+ z: 29, # Keyboard z and Z
43
+ :'1' => 30, # Keyboard 1 and !
44
+ :'2' => 31, # Keyboard 2 and @
45
+ :'3' => 32, # Keyboard 3 and #
46
+ :'4' => 33, # Keyboard 4 and $
47
+ :'5' => 34, # Keyboard 5 and %
48
+ :'6' => 35, # Keyboard 6 and ^
49
+ :'7' => 36, # Keyboard 7 and &
50
+ :'8' => 37, # Keyboard 8 and *
51
+ :'9' => 38, # Keyboard 9 and (
52
+ :'0' => 39, # Keyboard 0 and )
53
+ enter: 40, # Keyboard Return (ENTER)
54
+ esc: 41, # Keyboard ESCAPE
55
+ backspace: 42, # Keyboard DELETE (Backspace)
56
+ tab: 43, # Keyboard Tab
57
+ space: 44, # Keyboard Spacebar
58
+ minus: 45, # Keyboard - and _
59
+ equal: 46, # Keyboard = and +
60
+ leftbrace: 47, # Keyboard [ and {
61
+ rightbrace: 48, # Keyboard ] and }
62
+ backslash: 49, # Keyboard and |
63
+ hashtilde: 50, # Keyboard Non-US # and ~
64
+ semicolon: 51, # Keyboard ; and :
65
+ apostrophe: 52, # Keyboard ' and "
66
+ grave: 53, # Keyboard ` and ~
67
+ comma: 54, # Keyboard , and <
68
+ dot: 55, # Keyboard . and >
69
+ slash: 56, # Keyboard / and ?
70
+ capslock: 57, # Keyboard Caps Lock
71
+ f1: 58, # Keyboard F1
72
+ f2: 59, # Keyboard F2
73
+ f3: 60, # Keyboard F3
74
+ f4: 61, # Keyboard F4
75
+ f5: 62, # Keyboard F5
76
+ f6: 63, # Keyboard F6
77
+ f7: 64, # Keyboard F7
78
+ f8: 65, # Keyboard F8
79
+ f9: 66, # Keyboard F9
80
+ f10: 67, # Keyboard F10
81
+ f11: 68, # Keyboard F11
82
+ f12: 69, # Keyboard F12
83
+ sysrq: 70, # Keyboard Print Screen
84
+ scrolllock: 71, # Keyboard Scroll Lock
85
+ pause: 72, # Keyboard Pause
86
+ insert: 73, # Keyboard Insert
87
+ home: 74, # Keyboard Home
88
+ pageup: 75, # Keyboard Page Up
89
+ delete: 76, # Keyboard Delete Forward
90
+ _end: 77, # Keyboard End
91
+ pagedown: 78, # Keyboard Page Down
92
+ right: 79, # Keyboard Right Arrow
93
+ left: 80, # Keyboard Left Arrow
94
+ down: 81, # Keyboard Down Arrow
95
+ up: 82, # Keyboard Up Arrow
96
+ numlock: 83, # Keyboard Num Lock and Clear
97
+ kpslash: 84, # Keypad /
98
+ kpasterisk: 85, # Keypad *
99
+ kpminus: 86, # Keypad -
100
+ kpplus: 87, # Keypad +
101
+ kpenter: 88, # Keypad ENTER
102
+ kp1: 89, # Keypad 1 and End
103
+ kp2: 90, # Keypad 2 and Down Arrow
104
+ kp3: 91, # Keypad 3 and PageDn
105
+ kp4: 92, # Keypad 4 and Left Arrow
106
+ kp5: 93, # Keypad 5
107
+ kp6: 94, # Keypad 6 and Right Arrow
108
+ kp7: 95, # Keypad 7 and Home
109
+ kp8: 96, # Keypad 8 and Up Arrow
110
+ kp9: 97, # Keypad 9 and Page Up
111
+ kp0: 98, # Keypad 0 and Insert
112
+ kpdot: 99, # Keypad . and Delete
113
+ _102nd: 100, # Keyboard Non-US and |
114
+ compose: 101, # Keyboard Application
115
+ power: 102, # Keyboard Power
116
+ kpequal: 103, # Keypad =
117
+ f13: 104, # Keyboard F13
118
+ f14: 105, # Keyboard F14
119
+ f15: 106, # Keyboard F15
120
+ f16: 107, # Keyboard F16
121
+ f17: 108, # Keyboard F17
122
+ f18: 109, # Keyboard F18
123
+ f19: 110, # Keyboard F19
124
+ f20: 111, # Keyboard F20
125
+ f21: 112, # Keyboard F21
126
+ f22: 113, # Keyboard F22
127
+ f23: 114, # Keyboard F23
128
+ f24: 115, # Keyboard F24
129
+ open: 116, # Keyboard Execute
130
+ help: 117, # Keyboard Help
131
+ props: 118, # Keyboard Menu
132
+ front: 119, # Keyboard Select
133
+ stop: 120, # Keyboard Stop
134
+ again: 121, # Keyboard Again
135
+ undo: 122, # Keyboard Undo
136
+ cut: 123, # Keyboard Cut
137
+ copy: 124, # Keyboard Copy
138
+ paste: 125, # Keyboard Paste
139
+ find: 126, # Keyboard Find
140
+ mute: 127, # Keyboard Mute
141
+ volumeup: 128, # Keyboard Volume Up
142
+ volumedown: 129, # Keyboard Volume Down
143
+ kpcomma: 133, # Keypad Comma
144
+ ro: 135, # Keyboard International1
145
+ katakanahiragana: 136, # Keyboard International2
146
+ yen: 137, # Keyboard International3
147
+ henkan: 138, # Keyboard International4
148
+ muhenkan: 139, # Keyboard International5
149
+ kpjpcomma: 140, # Keyboard International6
150
+ hangeul: 144, # Keyboard LANG1
151
+ hanja: 145, # Keyboard LANG2
152
+ katakana: 146, # Keyboard LANG3
153
+ hiragana: 147, # Keyboard LANG4
154
+ zenkakuhankaku: 148, # Keyboard LANG5
155
+ kpleftparen: 182, # Keypad (
156
+ kprightparen: 183, # Keypad )
157
+ leftctrl: 224, # Keyboard Left Control
158
+ leftshift: 225, # Keyboard Left Shift
159
+ leftalt: 226, # Keyboard Left Alt
160
+ leftmeta: 227, # Keyboard Left GUI
161
+ rightctrl: 228, # Keyboard Right Control
162
+ rightshift: 229, # Keyboard Right Shift
163
+ rightalt: 230, # Keyboard Right Alt
164
+ rightmeta: 231, # Keyboard Right GUI
165
+ media_playpause: 232,
166
+ media_stopcd: 233,
167
+ media_previoussong: 234,
168
+ media_nextsong: 235,
169
+ media_ejectcd: 236,
170
+ media_volumeup: 237,
171
+ media_volumedown: 238,
172
+ media_mute: 239,
173
+ media_www: 240,
174
+ media_back: 241,
175
+ media_forward: 242,
176
+ media_stop: 243,
177
+ media_find: 244,
178
+ media_scrollup: 245,
179
+ media_scrolldown: 246,
180
+ media_edit: 247,
181
+ media_sleep: 248,
182
+ media_coffee: 249,
183
+ media_refresh: 250,
184
+ media_calc: 251
185
+ }
186
+
187
+ class HidG0
188
+
189
+ def initialize(dev='/dev/hidg0')
190
+ @dev = dev
191
+ end
192
+
193
+ def keypress(key)
194
+
195
+ write_report(NULL_CHAR*2 + KEYS[key.to_sym].chr + NULL_CHAR*5)
196
+
197
+ # Release keys
198
+ write_report(NULL_CHAR*8)
199
+
200
+ end
201
+
202
+ def sendkeys()
203
+ end
204
+
205
+ private
206
+
207
+ def write_report(report)
208
+ open(@dev, 'wb+') {|f| f.write report }
209
+ end
210
+ end
211
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hidg0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwMzEzMjAxMjI5WhcN
15
+ MjAwMzEyMjAxMjI5WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDDwLr3
17
+ mjbK3/PPmpZ+b474F3t9tTUSAROY7lq1HSygxzHPa7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IAcQWx6d
33
+ /KwboLCTigl112eg5ndLhMiWkG/IQpfK+ixi+pPXScCaGWwcpAsneO+VWVMa26rY
34
+ Q3sgcMkKiuN+fcbu4i4FPY1OCUArxlVE2c71C2MB4HVJL53jY9epetsWIJdwfQb8
35
+ PwTg5+TqjQvWRfpf4tDWra3/fS6sXSuA4aoh28J3YpuAS2upGYuCk61X4iEDYerh
36
+ INwakAqcXQ4/4DC0SoRunSvJ
37
+ -----END CERTIFICATE-----
38
+ date: 2019-03-13 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: james@jamesrobertson.eu
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - lib/hidg0.rb
47
+ homepage: https://github.com/jrobertson/hidg0
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.0.1
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Used with a Raspberry PI Zero plugged into a computer to act as USB Keyboard
70
+ (HID).
71
+ test_files: []
metadata.gz.sig ADDED
Binary file