Module: Vigilem::Win32API::Eventable Abstract

Included in:
InputSystemHandler
Defined in:
lib/vigilem/win32_api/eventable.rb

Overview

This module is abstract.

included into the same module as RubyizedAPI or respond_to? [:read_console_input, :peek_console_input]

Instance Method Summary collapse

Instance Method Details

#has_any?TrueClass || FalseClass

checks whether the input buffer has events

Returns:

  • (TrueClass || FalseClass)


37
38
39
# File 'lib/vigilem/win32_api/eventable.rb', line 37

def has_any?
  peek_console_input.size > 0
end

#read_many(number_of_events = 1) ⇒ Array

blocks until the specified number of events are read

Parameters:

  • number_of_events=1 (Integer)

Returns:

  • (Array)


16
17
18
# File 'lib/vigilem/win32_api/eventable.rb', line 16

def read_many(number_of_events=1)
  read_console_input({:nLength => number_of_events, :blocking => true })
end

#read_many_nonblock(limit = 1) ⇒ Array

Parameters:

  • limit (Integer) (defaults to: 1)

Returns:

  • (Array)


9
10
11
# File 'lib/vigilem/win32_api/eventable.rb', line 9

def read_many_nonblock(limit=1)
  [*(read_console_input({:nLength => limit, :blocking => false }) if has_any?)]
end

#read_oneArray

blocking reads one event from the input buffer

Returns:

  • (Array)


31
32
33
# File 'lib/vigilem/win32_api/eventable.rb', line 31

def read_one
  read_console_input.shift
end

#read_one_nonblockInputRecord

non_blocking commonly used with event processing

Parameters:

  • (Integer)

Returns:



24
25
26
# File 'lib/vigilem/win32_api/eventable.rb', line 24

def read_one_nonblock
  read_one if has_any?
end