vigilem-win32_api 0.0.10 → 0.0.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbde09d132a14953b05aeb4838acc918ab48c878
4
- data.tar.gz: 8a9eb4816a5a373fedd2838ce1fb05eba9305d90
3
+ metadata.gz: 1c295f6b135c5c95f699b1e222bcdae3651023c0
4
+ data.tar.gz: 49a302108d91627feb7cdd3e61b814ce844371d0
5
5
  SHA512:
6
- metadata.gz: 1cbfeaef82619e2b953cf1dc4da2c01756aebb4b32d41c869226e19090db8bca0af9dc8c6da2daa62bc61568bf127977efcb7fd0e889e2c79ec9a014d850c6ce
7
- data.tar.gz: 8d93eaf3ee72ae910bf61d06e33ff9f69e335167c34c4d939818d59130af29f64d9bf0a09b547b624ca68cc02b121c738f8f1fcb9b99cbc29a20125e09557af8
6
+ metadata.gz: 6b3404c15cc87a9d3976572fc95e6992f61847a4fa52658dd54b747ff7f575e0377a4a6c3d685adc270904755b4c3727e82cac54df4211944995fddc015d602e
7
+ data.tar.gz: 35e5f3a42dddf3cd18393c9738bc7c1895ace37c75a97d22887b74e70b5f5dcdd566059e3056c55b98c5e4530d8aee5e7bdbefce601d8c3716f9f8c9ba7c5e60
@@ -96,7 +96,7 @@ module Win32API
96
96
  # @param [Array] msgs
97
97
  # @return
98
98
  def demux(*msgs)
99
- hub.demux(self, *msgs)
99
+ hub.demux(self.buffer, *msgs)
100
100
  end
101
101
  private
102
102
 
@@ -51,7 +51,7 @@ module Keyboard
51
51
  # @param dw_state_names
52
52
  # @return [TrueClass || FalseClass]
53
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)
54
+ (control_pad_key?(virtual_key) or virtual_key == Keyboard::VK[:CLEAR]) and dw_state_names.include?(:ENHANCED_KEY)
55
55
  end
56
56
  end
57
57
 
@@ -1,5 +1,5 @@
1
1
  module Vigilem
2
2
  module Win32API
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.11'
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'ffi'
2
2
 
3
3
  require 'vigilem/win32_api/constants'
4
+ require 'vigilem/win32_api/virtual_keys/map'
4
5
 
5
6
  require 'vigilem/win32_api/types'
6
7
  require 'vigilem/win32_api/console_input_events'
@@ -10,48 +11,54 @@ require 'vigilem/win32_api/p_input__record'
10
11
 
11
12
  module Vigilem
12
13
 
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)
14
+ # @see http://msdn.microsoft.com for usage
15
+ # @todo consider FFI options Hash :blocking (Boolean) — default: @blocking — set to true if the C function is a blocking call
16
+ module Win32API
17
+ include Constants
18
+
19
+ VirtualKeys::Map.invert.each do |vk_name, int|
20
+ const_set(vk_name, int)
21
+ end
22
+
23
+ extend ::FFI::Library
24
+
25
+ ffi_lib 'kernel32', 'user32'
26
+ ffi_convention :stdcall
27
+
28
+ attach_function :GetStdHandle, [:DWORD], :HANDLE
29
+
30
+ attach_function :MapVirtualKeyW, [:UINT, :UINT], :UINT
31
+
32
+ module_function
33
+
34
+ def PeekConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
35
+ _PeekConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
36
+ end
37
+
38
+ def ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
39
+ _ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
40
+ end
41
+
42
+ def ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
43
+ _ReadConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
44
+ end
45
+
46
+ def WriteConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
47
+ _WriteConsoleInputW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead)
48
+ end
49
+
50
+ private
51
+
52
+ attach_function :_PeekConsoleInputW, :PeekConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
53
+
54
+ attach_function :_ReadConsoleInputW, :ReadConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
55
+
56
+ attach_function :_ReadConsoleInputW, :ReadConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
57
+
58
+ # future use
59
+ attach_function :_WriteConsoleInputW, :WriteConsoleInputW, [:HANDLE, :PINPUT_RECORD, :DWORD, :pointer], :BOOL
60
+
29
61
  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
62
  end
56
63
 
57
64
  require 'vigilem/win32_api/rubyized'
data/spec/spec_helper.rb CHANGED
@@ -8,12 +8,14 @@ require 'timeout'
8
8
 
9
9
  require 'vigilem/support/core_ext/debug_puts'
10
10
 
11
+ require 'vigilem/support/patch/ffi/pointer'
12
+
11
13
  require 'attributes_and_size_test'
12
14
 
13
15
  require 'input_helper'
14
16
 
15
17
  =begin
16
- #to discover when tests hang which will happen because I have not correctly isolated the tests
18
+ #to discover when tests hang, which will happen because I have not correctly isolated the tests
17
19
  # also can use rspec -f d
18
20
  RSpec.configure do |config|
19
21
 
@@ -1,4 +1,10 @@
1
- require 'timeout'
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/win32_api/eventable'
4
+
5
+ require 'vigilem/win32_api/input_system_handler'
6
+
7
+ require 'vigilem/core/adapters/adapter'
2
8
 
3
9
  describe Vigilem::Win32API::Eventable do
4
10
 
@@ -92,5 +98,37 @@ describe Vigilem::Win32API::Eventable do
92
98
  end
93
99
  end.to raise_error(Timeout::Error)
94
100
  end
101
+
102
+ context 'event_loop' do
103
+
104
+ let(:eventable_adapter) do
105
+ input_sys = double('InputSystem', :GetStdHandle => 3)
106
+ @incr = 0
107
+ allow(input_sys).to receive(:PeekConsoleInputW) do |hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead|
108
+ if @incr == 0
109
+ lpBuffer.replace(Vigilem::Win32API::PINPUT_RECORD.new(3,
110
+ Vigilem::Win32API::INPUT_RECORD[Vigilem::Win32API::KEY_EVENT, {:KeyEvent => [1, 1, 70, 33, {:UnicodeChar => 97}, 32]}]
111
+ ))
112
+ @incr += 1
113
+ end
114
+ 1
115
+ end
116
+ allow(input_sys).to receive(:ReadConsoleInputW) do |hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead|
117
+ lpBuffer.replace(Vigilem::Win32API::PINPUT_RECORD.new(3,
118
+ Vigilem::Win32API::INPUT_RECORD[Vigilem::Win32API::KEY_EVENT, {:KeyEvent => [1, 1, 70, 33, {:UnicodeChar => 97}, 32]}]
119
+ ))
120
+ 1
121
+ end
122
+ EventableAdapter.new(Vigilem::Win32API::InputSystemHandler.new(input_sys))
123
+ end
124
+
125
+ it 'will return one event per event in the win32 event queue' do # to check that there is parity between the input_system and here
126
+ expect([eventable_adapter.read_one_nonblock, eventable_adapter.read_one_nonblock]).to match [
127
+ instance_of(Vigilem::Win32API::INPUT_RECORD), nil
128
+ ]
129
+ end
130
+ end
131
+
95
132
  end
133
+
96
134
  end
@@ -4,6 +4,35 @@ require 'vigilem/win32_api/input_system_handler'
4
4
 
5
5
  describe Vigilem::Win32API::InputSystemHandler do
6
6
 
7
+ after(:each) do
8
+ Vigilem::Core::Hub.all.clear
9
+ end
10
+
11
+ describe '#hub' do
12
+ it 'returns a hub' do
13
+ expect(subject.hub).to match instance_of(Vigilem::Core::Hub)
14
+ end
15
+
16
+ it 'returns a hub that this buffer is attached to' do
17
+ expect(subject.hub.buffers).to match a_collection_including(subject.buffer)
18
+ end
19
+ end
20
+
21
+ describe '#demux' do
22
+
23
+ it 'demultiplexs events to other observers' do
24
+ subject.hub << (another_buffer = [])
25
+ subject.demux(*%w(a b c))
26
+ expect(another_buffer).to include(*%w(a b c))
27
+ end
28
+
29
+ it 'does not demultiplex to this buffer' do
30
+ subject.hub << (another_buffer = [])
31
+ subject.demux(*%w(a b c))
32
+ expect(subject.buffer).to be_empty
33
+ end
34
+ end
35
+
7
36
  describe '#GetStdHandle' do
8
37
 
9
38
  it 'forwards the call to the underlying system' do
@@ -68,6 +97,16 @@ describe Vigilem::Win32API::InputSystemHandler do
68
97
  end
69
98
  end
70
99
  context 'buffer > length' do
100
+
101
+ let(:args) do
102
+ {
103
+ :hConsoleInput => Vigilem::Win32API.GetStdHandle(Vigilem::Win32API::STD_INPUT_HANDLE),
104
+ :lpBuffer => Vigilem::Win32API::PINPUT_RECORD.new(len = 1),
105
+ :nLength => len,
106
+ :lpNumberOfEventsRead => FFI::MemoryPointer.new(:dword, 1)
107
+ }
108
+ end
109
+
71
110
  let(:input_record) { Vigilem::Win32API::INPUT_RECORD[Vigilem::Win32API::KEY_EVENT, {:KeyEvent => [1, 1, 70, 33, {:UnicodeChar => 97}, 32]}] }
72
111
  let!(:input_system) do
73
112
  subject.buffer.concat(3.times.map { input_record.dup })
@@ -79,15 +118,6 @@ describe Vigilem::Win32API::InputSystemHandler do
79
118
  subject
80
119
  end
81
120
 
82
- let(:args) do
83
- {
84
- :hConsoleInput => Vigilem::Win32API.GetStdHandle(Vigilem::Win32API::STD_INPUT_HANDLE),
85
- :lpBuffer => Vigilem::Win32API::PINPUT_RECORD.new(len = 1),
86
- :nLength => len,
87
- :lpNumberOfEventsRead => FFI::MemoryPointer.new(:dword, 1)
88
- }
89
- end
90
-
91
121
  it 'checks the buffer first then call the system' do
92
122
  expect(subject).to receive(:buffer).and_call_original
93
123
  subject.PeekConsoleInput(*args.values)
@@ -103,7 +133,8 @@ describe Vigilem::Win32API::InputSystemHandler do
103
133
 
104
134
  describe '#ReadConsoleInput' do
105
135
  context 'empty buffer' do
106
- let(:args) do
136
+
137
+ let(:args) do
107
138
  {
108
139
  :hConsoleInput => Vigilem::Win32API.GetStdHandle(Vigilem::Win32API::STD_INPUT_HANDLE),
109
140
  :lpBuffer => Vigilem::Win32API::PINPUT_RECORD.new(len = 3),
@@ -114,21 +145,31 @@ describe Vigilem::Win32API::InputSystemHandler do
114
145
 
115
146
  let(:input_record) { Vigilem::Win32API::INPUT_RECORD[Vigilem::Win32API::KEY_EVENT, {:KeyEvent => [1, 1, 70, 33, {:UnicodeChar => 97}, 32]}] }
116
147
 
117
- let!(:input_system) do
118
- lnk = spy(subject.send(:link), :semaphore => @monitor ||= Monitor.new)
119
- subject.send(:link=, lnk)
120
- allow(subject).to receive(:buffer).and_call_original
121
- allow(subject).to receive(:ReadConsoleInput).and_call_original
122
- subject.ReadConsoleInput(*args.values)
123
- subject
148
+ subject do
149
+ lnk = double('Vigilem::Win32API', :semaphore => @monitor ||= Monitor.new)
150
+ allow(lnk).to receive(:ReadConsoleInputW) do
151
+ args[:lpBuffer].replace([input_record])
152
+ 1
153
+ end
154
+ sub = described_class.new(lnk)
155
+ allow(sub).to receive(:buffer).and_call_original
156
+ allow(sub).to receive(:ReadConsoleInput).and_call_original
157
+ sub.ReadConsoleInput(*args.values)
158
+ sub
124
159
  end
125
160
 
161
+ before(:each) { subject }
162
+
126
163
  it 'checks the buffer first' do
127
- expect(input_system).to have_received(:buffer).at_least(:once)
164
+ expect(subject).to have_received(:buffer).at_least(:once)
128
165
  end
129
166
 
130
167
  it 'calls the link#ReadConsoleInput' do
131
- expect(input_system.send(:link)).to have_received(:ReadConsoleInputW).at_least(:once)
168
+ expect(subject.send(:link)).to have_received(:ReadConsoleInputW).at_least(:once)
169
+ end
170
+
171
+ it 'updates the lpBuffer' do
172
+ expect(args[:lpBuffer].size).to eql(1)
132
173
  end
133
174
  end
134
175
 
@@ -161,4 +202,37 @@ describe Vigilem::Win32API::InputSystemHandler do
161
202
 
162
203
  end
163
204
 
205
+ describe '#MapVirtualKey' do
206
+
207
+ let(:input_system) do
208
+ dbl = double('InputSystem')
209
+ allow(dbl).to receive(:MapVirtualKeyW)
210
+ end
211
+
212
+ subject do
213
+ sub = described_class.new(input_system)
214
+ allow(sub).to receive(:buffer).and_call_original
215
+ allow(sub).to receive(:MapVirtualKey).and_call_original
216
+ sub
217
+ end
218
+
219
+ it 'calls the underlying #MapVirtualKeyW on the input_system' do
220
+ expect(input_system).to receive(:MapVirtualKeyW)
221
+ subject.MapVirtualKey(Vigilem::Win32API::VK_LSHIFT, Vigilem::Win32API::MAPVK_VK_TO_VSC)
222
+ end
223
+
224
+ it 'raises an ArgumentError if uCode is not an Integer' do
225
+ expect do
226
+ subject.MapVirtualKey(:VK_LSHIFT, Vigilem::Win32API::MAPVK_VK_TO_VSC)
227
+ end.to raise_error(ArgumentError)
228
+ end
229
+
230
+ it 'raises an ArgumentError if uMapType is not an Integer' do
231
+ expect do
232
+ subject.MapVirtualKey(Vigilem::Win32API::VK_LSHIFT, :MAPVK_VK_TO_VSC)
233
+ end.to raise_error(ArgumentError)
234
+ end
235
+
236
+ end
237
+
164
238
  end
@@ -44,13 +44,13 @@ describe (KB = Vigilem::Win32API::Utils::Keyboard) do
44
44
  end
45
45
  end
46
46
 
47
- describe '::nav_control_pad_key?' do
47
+ describe '::nav_control_key?' do
48
48
  it 'returns true if the key is one that is above the nav arrow pad' do
49
- expect(KB.nav_control_pad_key?(KB::VK[:NEXT], :ENHANCED_KEY, :SOME_OTHER_KEY)).to be_truthy
49
+ expect(KB.nav_control_key?(KB::VK[:NEXT], :ENHANCED_KEY, :SOME_OTHER_KEY)).to be_truthy
50
50
  end
51
51
 
52
52
  it 'returns false if the key is one that is not above the nav arrow pad' do
53
- expect(KB.nav_control_pad_key?(1, :ENHANCED_KEY)).to be_falsey
53
+ expect(KB.nav_control_key?(1, :ENHANCED_KEY)).to be_falsey
54
54
  end
55
55
  end
56
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigilem-win32_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - jtzero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vigilem-dom