vigilem-win32_api 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/lib/vigilem/win32_api/console_input_events.rb +78 -0
  4. data/lib/vigilem/win32_api/constants.rb +97 -0
  5. data/lib/vigilem/win32_api/dom/adapter.rb +59 -0
  6. data/lib/vigilem/win32_api/dom/code_values_tables.rb +136 -0
  7. data/lib/vigilem/win32_api/dom/input_record_utils.rb +259 -0
  8. data/lib/vigilem/win32_api/dom/key_values_tables.rb +123 -0
  9. data/lib/vigilem/win32_api/dom.rb +5 -0
  10. data/lib/vigilem/win32_api/eventable.rb +41 -0
  11. data/lib/vigilem/win32_api/input__record.rb +53 -0
  12. data/lib/vigilem/win32_api/input_system_handler.rb +124 -0
  13. data/lib/vigilem/win32_api/p_input__record.rb +55 -0
  14. data/lib/vigilem/win32_api/rubyized.rb +114 -0
  15. data/lib/vigilem/win32_api/types.rb +153 -0
  16. data/lib/vigilem/win32_api/utils/keyboard.rb +120 -0
  17. data/lib/vigilem/win32_api/version.rb +5 -0
  18. data/lib/vigilem/win32_api/virtual_keys/map.rb +211 -0
  19. data/lib/vigilem/win32_api/virtual_keys.rb +9 -0
  20. data/lib/vigilem/win32_api.rb +61 -0
  21. data/spec/acceptance/custom_input_system.feature +3 -0
  22. data/spec/acceptance/dom_adapter.feature +7 -0
  23. data/spec/acceptance/rubyized.feature +6 -0
  24. data/spec/acceptance/steps/custom_input_system_steps.rb +37 -0
  25. data/spec/acceptance/steps/dom_adapter_steps.rb +7 -0
  26. data/spec/acceptance/steps/rubyized_steps.rb +20 -0
  27. data/spec/attributes_and_size_test.rb +10 -0
  28. data/spec/input_helper.rb +41 -0
  29. data/spec/spec_helper.rb +28 -0
  30. data/spec/turnip_helper.rb +1 -0
  31. data/spec/vigilem/api_spec.rb +139 -0
  32. data/spec/vigilem/win32_api/console_input_events_spec.rb +67 -0
  33. data/spec/vigilem/win32_api/dom/adapter_spec.rb +164 -0
  34. data/spec/vigilem/win32_api/dom/code_values_tables_spec.rb +5 -0
  35. data/spec/vigilem/win32_api/dom/input_record_utils_spec.rb +255 -0
  36. data/spec/vigilem/win32_api/dom/key_values_tables_spec.rb +5 -0
  37. data/spec/vigilem/win32_api/eventable_spec.rb +96 -0
  38. data/spec/vigilem/win32_api/input__record_spec.rb +113 -0
  39. data/spec/vigilem/win32_api/input_system_handler_spec.rb +164 -0
  40. data/spec/vigilem/win32_api/p_input__record_spec.rb +43 -0
  41. data/spec/vigilem/win32_api/rubyized_spec.rb +134 -0
  42. data/spec/vigilem/win32_api/types_spec.rb +139 -0
  43. data/spec/vigilem/win32_api/utils/keyboard_spec.rb +126 -0
  44. data/spec/vigilem/win32_api/virtual_keys/map_spec.rb +10 -0
  45. data/spec/vigilem/win32_api/virtual_keys_spec.rb +28 -0
  46. metadata +225 -0
@@ -0,0 +1,120 @@
1
+ require 'vigilem/win32_api/virtual_keys'
2
+
3
+ module Vigilem::Win32API
4
+ module Utils
5
+ # http://www.w3.org/TR/2013/WD-uievents-20130725/keyboard-sections.svg
6
+ # http://www.computer-hardware-explained.com/image-files/computer-keyboard-layout-explained.jpg
7
+ # https://upload.wikimedia.org/wikipedia/commons/9/9c/ISO_keyboard_%28105%29_QWERTY_UK.svg
8
+ # http://i.stack.imgur.com/FU0R2.png
9
+ #
10
+ module Keyboard
11
+
12
+ include Vigilem::Win32API::VirtualKeys
13
+
14
+ #
15
+ #
16
+ module ControlPadKeys
17
+
18
+ #
19
+ # @param virtual_key
20
+ # @return [TrueClass || FalseClass]
21
+ def control_pad_key?(virtual_key)
22
+ [Keyboard::VK[:INSERT], Keyboard::VK[:DELETE], Keyboard::VK[:PRIOR], Keyboard::VK[:NEXT], Keyboard::VK[:END], Keyboard::VK[:HOME]].include?(virtual_key)
23
+ end
24
+ end
25
+
26
+ include ControlPadKeys
27
+ extend ControlPadKeys
28
+
29
+ #
30
+ #
31
+ module NavigationKeys
32
+
33
+ #
34
+ # @param virtual_key
35
+ # @return [TrueClass || FalseClass]
36
+ def arrow_key?(virtual_key)
37
+ virtual_key.between?(Keyboard::VK[:LEFT], Keyboard::VK[:DOWN])
38
+ end
39
+
40
+ #
41
+ # @param virtual_key
42
+ # @param dw_state_names
43
+ # @return [TrueClass || FalseClass]
44
+ def nav_arrow_key?(virtual_key, *dw_state_names)
45
+ arrow_key?(virtual_key) and dw_state_names.include?(:ENHANCED_KEY)
46
+ end
47
+
48
+ # the pad above the arrow keys, what is CLEAR again?
49
+ #
50
+ # @param virtual_key
51
+ # @param dw_state_names
52
+ # @return [TrueClass || FalseClass]
53
+ def nav_control_key?(virtual_key, *dw_state_names)
54
+ (control_key?(virtual_key) or virtual_key == Keyboard::VK[:CLEAR]) and dw_state_names.include?(:ENHANCED_KEY)
55
+ end
56
+ end
57
+
58
+ include NavigationKeys
59
+ extend NavigationKeys
60
+
61
+ #
62
+ #
63
+ module NumpadKeys
64
+
65
+ #
66
+ # @param virtual_key
67
+ # @return [TrueClass || FalseClass]
68
+ def numlock?(virtual_key)
69
+ virtual_key == Keyboard::VK[:NUMLOCK]
70
+ end
71
+
72
+ #
73
+ # @param virtual_key
74
+ # @param [Array] dw_state_names
75
+ # @return [TrueClass || FalseClass]
76
+ def numpad_return?(virtual_key, *dw_state_names)
77
+ virtual_key == 0x0D and dw_state_names.include?(:ENHANCED_KEY)
78
+ end
79
+
80
+ #
81
+ # numpad_except_return_or_numlock
82
+ # @param virtual_key
83
+ # @return [TrueClass || FalseClass]
84
+ def numpad_number_function?(virtual_key)
85
+ virtual_key.between?(Keyboard::VK[:NUMPAD0], Keyboard::VK[:DIVIDE])
86
+ end
87
+
88
+ #
89
+ # @param virtual_key
90
+ # @param [Array] dw_state_names
91
+ # @return [TrueClass || FalseClass]
92
+ def numpad_arrow?(virtual_key, *dw_state_names)
93
+ arrow_key?(virtual_key) and not dw_state_names.include?(:ENHANCED_KEY)
94
+ end
95
+
96
+ #
97
+ # @param virtual_key
98
+ # @param [Array] dw_state_names
99
+ # @return [TrueClass || FalseClass]
100
+ def numpad_control_key?(virtual_key, *dw_state_names)
101
+ control_pad_key?(virtual_key) and not dw_state_names.include?(:ENHANCED_KEY)
102
+ end
103
+
104
+ #
105
+ # @param virtual_key
106
+ # @param [Array] dw_state_names
107
+ # @return [TrueClass || FalseClass]
108
+ def numpad?(virtual_key, *dw_state_names)
109
+ numpad_return?(virtual_key, *dw_state_names) or numpad_number_function?(virtual_key) or
110
+ numlock?(virtual_key) or numpad_control_key?(virtual_key, *dw_state_names)
111
+ end
112
+
113
+ end
114
+
115
+ include NumpadKeys
116
+ extend NumpadKeys
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,5 @@
1
+ module Vigilem
2
+ module Win32API
3
+ VERSION = '0.0.10'
4
+ end
5
+ end
@@ -0,0 +1,211 @@
1
+ require 'vigilem/support/key_map'
2
+
3
+ module Vigilem
4
+ module Win32API
5
+ # https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
6
+ module VirtualKeys
7
+ Map = Support::KeyMap.new({
8
+ 0x01 => :VK_LBUTTON,
9
+ 0x02 => :VK_RBUTTON,
10
+ 0x03 => :VK_CANCEL,
11
+ 0x04 => :VK_MBUTTON,
12
+ 0x05 => :VK_XBUTTON1,
13
+ 0x06 => :VK_XBUTTON2,
14
+ [0x07, 0x0A..0x0B, 0x0E..0x0F, 0x16, 0x1A,
15
+ 0x3A..0x40, 0x5E, 0x88..0x8F, 0x97..0x9F,
16
+ 0xB8..0xB9, 0xC1..0xD7, 0xD8..0xDA, 0xE0, 0xE8] => :VK_UNASSIGNED,
17
+ 0x08 => :VK_BACK,
18
+ 0x09 => :VK_TAB,
19
+ 0x0C => :VK_CLEAR,
20
+ 0x0D => :VK_RETURN,
21
+ 0x10 => :VK_SHIFT,
22
+ 0x11 => :VK_CONTROL,
23
+ 0x12 => :VK_MENU,
24
+ 0x13 => :VK_PAUSE,
25
+ 0x14 => :VK_CAPITAL,
26
+ 0x15 => :VK_KANA,
27
+ 0x15 => :VK_HANGUEL,
28
+ 0x15 => :VK_HANGUL,
29
+ 0x17 => :VK_JUNJA,
30
+ 0x18 => :VK_FINAL,
31
+ 0x19 => :VK_HANJA,
32
+ 0x19 => :VK_KANJI,
33
+ 0x1B => :VK_ESCAPE,
34
+ 0x1C => :VK_CONVERT,
35
+ 0x1D => :VK_NONCONVERT,
36
+ 0x1E => :VK_ACCEPT,
37
+ 0x1F => :VK_MODECHANGE,
38
+ 0x20 => :VK_SPACE,
39
+ 0x21 => :VK_PRIOR,
40
+ 0x22 => :VK_NEXT,
41
+ 0x23 => :VK_END,
42
+ 0x24 => :VK_HOME,
43
+ 0x25 => :VK_LEFT,
44
+ 0x26 => :VK_UP,
45
+ 0x27 => :VK_RIGHT,
46
+ 0x28 => :VK_DOWN,
47
+ 0x29 => :VK_SELECT,
48
+ 0x2A => :VK_PRINT,
49
+ 0x2B => :VK_EXECUTE,
50
+ 0x2C => :VK_SNAPSHOT,
51
+ 0x2D => :VK_INSERT,
52
+ 0x2E => :VK_DELETE,
53
+ 0x2F => :VK_HELP,
54
+ 0x30 => :VK_0,
55
+ 0x31 => :VK_1,
56
+ 0x32 => :VK_2,
57
+ 0x33 => :VK_3,
58
+ 0x34 => :VK_4,
59
+ 0x35 => :VK_5,
60
+ 0x36 => :VK_6,
61
+ 0x37 => :VK_7,
62
+ 0x38 => :VK_8,
63
+ 0x39 => :VK_9,
64
+ 0x41 => :VK_A,
65
+ 0x42 => :VK_B,
66
+ 0x43 => :VK_C,
67
+ 0x44 => :VK_D,
68
+ 0x45 => :VK_E,
69
+ 0x46 => :VK_F,
70
+ 0x47 => :VK_G,
71
+ 0x48 => :VK_H,
72
+ 0x49 => :VK_I,
73
+ 0x4A => :VK_J,
74
+ 0x4B => :VK_K,
75
+ 0x4C => :VK_L,
76
+ 0x4D => :VK_M,
77
+ 0x4E => :VK_N,
78
+ 0x4F => :VK_O,
79
+ 0x50 => :VK_P,
80
+ 0x51 => :VK_Q,
81
+ 0x52 => :VK_R,
82
+ 0x53 => :VK_S,
83
+ 0x54 => :VK_T,
84
+ 0x55 => :VK_U,
85
+ 0x56 => :VK_V,
86
+ 0x57 => :VK_W,
87
+ 0x58 => :VK_X,
88
+ 0x59 => :VK_Y,
89
+ 0x5A => :VK_Z,
90
+ 0x5B => :VK_LWIN,
91
+ 0x5C => :VK_RWIN,
92
+ 0x5D => :VK_APPS,
93
+ 0x5F => :VK_SLEEP,
94
+ 0x60 => :VK_NUMPAD0,
95
+ 0x61 => :VK_NUMPAD1,
96
+ 0x62 => :VK_NUMPAD2,
97
+ 0x63 => :VK_NUMPAD3,
98
+ 0x64 => :VK_NUMPAD4,
99
+ 0x65 => :VK_NUMPAD5,
100
+ 0x66 => :VK_NUMPAD6,
101
+ 0x67 => :VK_NUMPAD7,
102
+ 0x68 => :VK_NUMPAD8,
103
+ 0x69 => :VK_NUMPAD9,
104
+ 0x6A => :VK_MULTIPLY,
105
+ 0x6B => :VK_ADD,
106
+ 0x6C => :VK_SEPARATOR,
107
+ 0x6D => :VK_SUBTRACT,
108
+ 0x6E => :VK_DECIMAL,
109
+ 0x6F => :VK_DIVIDE,
110
+ 0x70 => :VK_F1,
111
+ 0x71 => :VK_F2,
112
+ 0x72 => :VK_F3,
113
+ 0x73 => :VK_F4,
114
+ 0x74 => :VK_F5,
115
+ 0x75 => :VK_F6,
116
+ 0x76 => :VK_F7,
117
+ 0x77 => :VK_F8,
118
+ 0x78 => :VK_F9,
119
+ 0x79 => :VK_F10,
120
+ 0x7A => :VK_F11,
121
+ 0x7B => :VK_F12,
122
+ 0x7C => :VK_F13,
123
+ 0x7D => :VK_F14,
124
+ 0x7E => :VK_F15,
125
+ 0x7F => :VK_F16,
126
+ 0x80 => :VK_F17,
127
+ 0x81 => :VK_F18,
128
+ 0x82 => :VK_F19,
129
+ 0x83 => :VK_F20,
130
+ 0x84 => :VK_F21,
131
+ 0x85 => :VK_F22,
132
+ 0x86 => :VK_F23,
133
+ 0x87 => :VK_F24,
134
+ 0x90 => :VK_NUMLOCK,
135
+ 0x91 => :VK_SCROLL,
136
+ [0x92..0x96, 0xE3..0xE4, 0xE9..0xF5] => :VK_OEM,
137
+ 0xA0 => :VK_LSHIFT,
138
+ 0xA1 => :VK_RSHIFT,
139
+ 0xA2 => :VK_LCONTROL,
140
+ 0xA3 => :VK_RCONTROL,
141
+ 0xA4 => :VK_LMENU,
142
+ 0xA5 => :VK_RMENU,
143
+ 0xA6 => :VK_BROWSER_BACK,
144
+ 0xA7 => :VK_BROWSER_FORWARD,
145
+ 0xA8 => :VK_BROWSER_REFRESH,
146
+ 0xA9 => :VK_BROWSER_STOP,
147
+ 0xAA => :VK_BROWSER_SEARCH,
148
+ 0xAB => :VK_BROWSER_FAVORITES,
149
+ 0xAC => :VK_BROWSER_HOME,
150
+ 0xAD => :VK_VOLUME_MUTE,
151
+ 0xAE => :VK_VOLUME_DOWN,
152
+ 0xAF => :VK_VOLUME_UP,
153
+ 0xB0 => :VK_MEDIA_NEXT_TRACK,
154
+ 0xB1 => :VK_MEDIA_PREV_TRACK,
155
+ 0xB2 => :VK_MEDIA_STOP,
156
+ 0xB3 => :VK_MEDIA_PLAY_PAUSE,
157
+ 0xB4 => :VK_LAUNCH_MAIL,
158
+ 0xB5 => :VK_LAUNCH_MEDIA_SELECT,
159
+ 0xB6 => :VK_LAUNCH_APP1,
160
+ 0xB7 => :VK_LAUNCH_APP2,
161
+ 0xBA => :VK_OEM_1,
162
+ 0xBB => :VK_OEM_PLUS,
163
+ 0xBC => :VK_OEM_COMMA,
164
+ 0xBD => :VK_OEM_MINUS,
165
+ 0xBE => :VK_OEM_PERIOD,
166
+ 0xBF => :VK_OEM_2,
167
+ 0xC0 => :VK_OEM_3,
168
+ 0xDB => :VK_OEM_4,
169
+ 0xDC => :VK_OEM_5,
170
+ 0xDD => :VK_OEM_6,
171
+ 0xDE => :VK_OEM_7,
172
+ 0xDF => :VK_OEM_8,
173
+ 0xE1 => :VK_OEM,
174
+ 0xE2 => :VK_OEM_102,
175
+ 0xE5 => :VK_PROCESSKEY,
176
+ 0xE6 => :VK_OEM,
177
+ 0xE7 => :VK_PACKET,
178
+ 0xF6 => :VK_ATTN,
179
+ 0xF7 => :VK_CRSEL,
180
+ 0xF8 => :VK_EXSEL,
181
+ 0xF9 => :VK_EREOF,
182
+ 0xFA => :VK_PLAY,
183
+ 0xFB => :VK_ZOOM,
184
+ 0xFC => :VK_NONAME,
185
+ 0xFD => :VK_PA1,
186
+ 0xFE => :VK_OEM_CLEAR,
187
+ 0xF2 => :VK_OEM_COPY,
188
+ 0xF3 => :VK_OEM_AUTO,
189
+ 0xF4 => :VK_OEM_ENLW,
190
+ 0xF5 => :VK_OEM_BACKTAB #"RomanCharacters" for Japanese keyboard layout, "Unidentified" for the others.
191
+ })
192
+
193
+ # windows uses "Virtual-Key Codes" format
194
+ code_aliases = [:dom_key, :virtual_key_code, :virtual_key_codes]
195
+ vk_aliases = :win_vk, :virtual_key, :virtual_keys, :virtual_keyname, :virtual_keynames
196
+
197
+ VK = Map.class.new
198
+
199
+ Map.left_side_aliases(*code_aliases)
200
+ VK.left_side_aliases(*vk_aliases)
201
+
202
+ Map.right_side_aliases(*vk_aliases)
203
+ VK.right_side_aliases(*code_aliases)
204
+
205
+ Map.each_with_object(VK) do |(key, value), hsh|
206
+ vk_name = value.to_s[3..-1]
207
+ hsh[sym = :"#{vk_name}"] = key
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,9 @@
1
+ require 'vigilem/win32_api/virtual_keys/map'
2
+
3
+ module Vigilem::Win32API
4
+
5
+ #
6
+ module VirtualKeys
7
+ Map.each {|num, name| const_set(name, num) unless const_defined?(name) }
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ require 'ffi'
2
+
3
+ require 'vigilem/win32_api/constants'
4
+
5
+ require 'vigilem/win32_api/types'
6
+ require 'vigilem/win32_api/console_input_events'
7
+
8
+ require 'vigilem/win32_api/input__record'
9
+ require 'vigilem/win32_api/p_input__record'
10
+
11
+ module Vigilem
12
+
13
+ # @see http://msdn.microsoft.com for usage
14
+ # @todo consider FFI options Hash :blocking (Boolean) — default: @blocking — set to true if the C function is a blocking call
15
+ module Win32API
16
+ extend ::FFI::Library
17
+
18
+ ffi_lib 'kernel32', 'user32'
19
+ ffi_convention :stdcall
20
+
21
+ attach_function :GetStdHandle, [:DWORD], :HANDLE
22
+
23
+ attach_function :MapVirtualKeyW, [:UINT, :UINT], :UINT
24
+
25
+ module_function
26
+
27
+ def PeekConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
28
+ _PeekConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
29
+ end
30
+
31
+ def ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
32
+ _ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
33
+ end
34
+
35
+ def ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
36
+ _ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
37
+ end
38
+
39
+ def WriteConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
40
+ _WriteConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
41
+ end
42
+
43
+ private
44
+
45
+ attach_function :_PeekConsoleInputW, :PeekConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
46
+
47
+ attach_function :_ReadConsoleInputW, :ReadConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
48
+
49
+ attach_function :_ReadConsoleInputW, :ReadConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
50
+
51
+ # future use
52
+ attach_function :_WriteConsoleInputW, :WriteConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
53
+
54
+ end
55
+ end
56
+
57
+ require 'vigilem/win32_api/rubyized'
58
+
59
+ require 'vigilem/win32_api/input_system_handler'
60
+
61
+ require 'vigilem/win32_api/dom'
@@ -0,0 +1,3 @@
1
+ #Feature: Allow the input system to be changed and customized
2
+
3
+
@@ -0,0 +1,7 @@
1
+ #Feature: Provide a DOM Adapter for the Win32 API
2
+
3
+ #Scenario: get DOM events from api
4
+ # this is badly formed @see the step for the reason why
5
+ #Given read_console_input called before user presses a key
6
+ #Then a PINPUT_RECORD is returned
7
+
@@ -0,0 +1,6 @@
1
+ Feature: Provide a simple win 32 api for the dev
2
+
3
+ Scenario: get events from api
4
+ # this is badly formed @see the step for the reason why
5
+ Given read_console_input called before user presses a key
6
+ Then a PINPUT_RECORD is returned
@@ -0,0 +1,37 @@
1
+ =begin
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'vigilem/win32'
6
+
7
+ require 'vigilem/win32_api/event_common'
8
+
9
+ include Vigilem::Win32API
10
+
11
+ module FakeInputSystem
12
+ class << self
13
+
14
+ INPUT_RECORD = Vigilem::Win32API::INPUT_RECORD
15
+
16
+ def GetStdHandle(arg)
17
+ 3
18
+ end
19
+
20
+ def PeekConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
21
+ lpBuffer.replace([INPUT_RECORD.new])
22
+ 1
23
+ end
24
+
25
+ def ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
26
+ lpBuffer.replace([INPUT_RECORD.new])
27
+ 1
28
+ end
29
+ end
30
+ end
31
+
32
+ adapt = EventCommon::Adapter.new.attach(InputSystemHandler.new(FakeInputSystem))
33
+
34
+ puts 'press a button'
35
+
36
+ puts adapt.read_console_input.inspect
37
+ =end
@@ -0,0 +1,7 @@
1
+ #require 'vigilem/win32_api/dom'
2
+
3
+ module DomAdapterSteps
4
+
5
+ #step
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module RubyizedSteps
4
+
5
+ include InputHelper
6
+
7
+ # this is malformed but due do timing and blocking this si the best way
8
+ step 'read_console_input called before user presses a key' do
9
+ adapt = InputSystemHandler.new
10
+ flush
11
+ write_console_input_test
12
+ @api_return = adapt.read_console_input
13
+ end
14
+
15
+ step 'a PINPUT_RECORD is returned' do
16
+ expect(@api_return).to be_a ::Vigilem::Win32API::PINPUT_RECORD
17
+ end
18
+ end
19
+
20
+ RSpec.configure { |c| c.include RubyizedSteps }
@@ -0,0 +1,10 @@
1
+ shared_examples 'attributes_and_size_test' do
2
+
3
+ it 'will have methods as attrs' do
4
+ expect(described_class.new).to respond_to(*ary)
5
+ end
6
+
7
+ it %q(will have an size eql to it's layout types sizes) do
8
+ expect(described_class.new.to_ptr.type_size).to eql(sze)
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ require 'fiddle/import'
2
+
3
+ module InputHelper
4
+ include Vigilem::Win32API
5
+
6
+ module Fid
7
+ require 'fiddle/types'
8
+
9
+ extend Fiddle::Importer
10
+
11
+ dlload 'kernel32.dll', 'user32.dll'
12
+
13
+ include Fiddle::Win32Types
14
+
15
+ extern 'HANDLE GetStdHandle(DWORD)', :stdcall
16
+
17
+ extern 'BOOL FlushConsoleInputBuffer(HANDLE)', :stdcall
18
+
19
+ extern 'BOOL WriteConsoleInput(HANDLE, PVOID, DWORD, PVOID)', :stdcall
20
+ end
21
+
22
+ def std_handle
23
+ Fid.GetStdHandle(0xFFFFFFF6)
24
+ end
25
+
26
+ # clear out the user entered stuff queue
27
+ def flush
28
+ Fid.FlushConsoleInputBuffer(std_handle)
29
+ end
30
+
31
+ def write_console_input_test
32
+ nLength ||= 20
33
+ lpNumberOfEventsWritten ||= ' ' * 4
34
+ Fid.WriteConsoleInput(std_handle, [0x0001, 1, 0, 0x61, 1, 0x41, 97].pack('SxxlSSSSL'),
35
+ nLength, lpNumberOfEventsWritten)
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |c|
40
+ c.include InputHelper
41
+ end
@@ -0,0 +1,28 @@
1
+ # @todo metal events need to be in another windows console
2
+ # @todo alot of the receive methods are too brittle
3
+
4
+ require 'bundler'
5
+ Bundler.setup
6
+
7
+ require 'timeout'
8
+
9
+ require 'vigilem/support/core_ext/debug_puts'
10
+
11
+ require 'attributes_and_size_test'
12
+
13
+ require 'input_helper'
14
+
15
+ =begin
16
+ #to discover when tests hang which will happen because I have not correctly isolated the tests
17
+ # also can use rspec -f d
18
+ RSpec.configure do |config|
19
+
20
+ config.before :all do |example_group|
21
+ puts "#{example_group.class.description}"
22
+ end
23
+
24
+ config.before :each do |example|
25
+ puts "->#{example.description}"
26
+ end
27
+ end
28
+ =end
@@ -0,0 +1 @@
1
+ Dir.glob("spec/acceptance/steps/**/*_steps.rb") { |f| load f, true }