Module: Vigilem::Win32API::Rubyized Abstract

Includes:
Constants
Included in:
InputSystemHandler
Defined in:
lib/vigilem/win32_api/rubyized.rb

Overview

This module is abstract.

Constant Summary

Constants included from Constants

Constants::BACKGROUND_BLUE, Constants::BACKGROUND_GREEN, Constants::BACKGROUND_INTENSITY, Constants::BACKGROUND_RED, Constants::CONSOLE_TEXTMODE_BUFFER, Constants::DOUBLE_CLICK, Constants::ENABLE_ECHO_INPUT, Constants::ENABLE_LINE_INPUT, Constants::ENABLE_MOUSE_INPUT, Constants::ENABLE_PROCESSED_INPUT, Constants::ENABLE_PROCESSED_OUTPUT, Constants::ENABLE_WINDOW_INPUT, Constants::ENABLE_WRAP_AT_EOL_OUTPUT, Constants::FILE_SHARE_READ, Constants::FILE_SHARE_WRITE, Constants::FOREGROUND_BLUE, Constants::FOREGROUND_GREEN, Constants::FOREGROUND_INTENSITY, Constants::FOREGROUND_RED, Constants::FROM_LEFT_1ST_BUTTON_PRESSED, Constants::FROM_LEFT_2ND_BUTTON_PRESSED, Constants::FROM_LEFT_3RD_BUTTON_PRESSED, Constants::FROM_LEFT_4TH_BUTTON_PRESSED, Constants::GENERIC_READ, Constants::GENERIC_WRITE, Constants::INVALID_HANDLE_VALUE, Constants::MOUSE_MOVED, Constants::MOUSE_WHEELED, Constants::MapVK, Constants::RIGHTMOST_BUTTON_PRESSED, Constants::STD_ERROR_HANDLE, Constants::STD_INPUT_HANDLE, Constants::STD_OUTPUT_HANDLE

Constants included from Constants::MapType

Constants::MapType::MAPVK, Constants::MapType::MAPVK_VK_TO_CHAR, Constants::MapType::MAPVK_VK_TO_VSC, Constants::MapType::MAPVK_VSC_TO_VK, Constants::MapType::MAPVK_VSC_TO_VK_EX

Constants included from Constants::Events

Constants::Events::CTRL_BREAK_EVENT, Constants::Events::CTRL_CLOSE_EVENT, Constants::Events::CTRL_C_EVENT, Constants::Events::CTRL_LOGOFF_EVENT, Constants::Events::CTRL_SHUTDOWN_EVENT, Constants::Events::FOCUS_EVENT, Constants::Events::KEY_EVENT, Constants::Events::MENU_EVENT, Constants::Events::MOUSE_EVENT, Constants::Events::WINDOW_BUFFER_SIZE_EVENT

Constants included from Constants::DWControlKeys

Constants::DWControlKeys::CAPSLOCK_ON, Constants::DWControlKeys::ENHANCED_KEY, Constants::DWControlKeys::LEFT_ALT_PRESSED, Constants::DWControlKeys::LEFT_CTRL_PRESSED, Constants::DWControlKeys::NUMLOCK_ON, Constants::DWControlKeys::RIGHT_ALT_PRESSED, Constants::DWControlKeys::RIGHT_CTRL_PRESSED, Constants::DWControlKeys::SCROLLLOCK_ON, Constants::DWControlKeys::SHIFT_PRESSED

Instance Method Summary collapse

Instance Method Details

#get_std_handle(handle = Vigilem::Win32API::STD_INPUT_HANDLE) ⇒ Integer

Parameters:

  • handle (Integer) (defaults to: Vigilem::Win32API::STD_INPUT_HANDLE)

    defaults to Vigilem::Win32API::STD_INPUT_HANDLE

Returns:

  • (Integer)


13
14
15
# File 'lib/vigilem/win32_api/rubyized.rb', line 13

def get_std_handle(handle=Vigilem::Win32API::STD_INPUT_HANDLE)
  win32_api_rubyized_src.GetStdHandle(handle)
end

#map_virtual_key(code, conversion) ⇒ Integer

Translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code.

Parameters:

  • code, (Integer)

    the uCode

  • conversion, (Symbol || Integer)

    the uMapType, Vigilem::Win32API::Constants::MapType

Returns:

  • (Integer)

Raises:

  • ArgumentError when conversion is a Symbol and not a valid uMapType name

  • ArgumentError when conversion is a Integer and not a valid uMapType code



63
64
65
66
67
68
69
70
71
# File 'lib/vigilem/win32_api/rubyized.rb', line 63

def map_virtual_key(code, conversion)
  conversion_value = if conversion.is_a? Symbol
    raise ArgumentError, "`#{conversion}' is not an available uMapType name" unless MapType.constants.include? conversion
    API::Rubyized.const_get(conversion)
  elsif not (@uMapeTypes ||= MapType.constants.map {|const| Vigilem::Win32API::Rubyized.const_get(const) }).include? conversion
    raise ArgumentError, "`#{conversion}' is not an available uMapType" 
  end
  win32_api_rubyized_src.MapVirtualKey(code, conversion_value || conversion)
end

#peek_console_input(opts = {}) ⇒ PINPUT_RECORD

Parameters:

  • (Hash)
  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :hConsoleInput (Integer)
  • :lpBuffer (PINPUT_RECORD || Array)
  • :nLength (Integer)
  • :lpNumberOfEventsRead (Integer)

Returns:



24
25
26
27
28
# File 'lib/vigilem/win32_api/rubyized.rb', line 24

def peek_console_input(opts={})
  _options(opts)
  win32_api_rubyized_src.PeekConsoleInput(opts[:hConsoleInput], opts[:lpBuffer], opts[:nLength], opts[:lpNumberOfEventsRead])
  opts[:lpBuffer]
end

#read_console_input(opts = {}) ⇒ PINPUT_RECORD

default behaviour is that of read_console_input (block if no msgs in the buffer, if opts == true, the method will block until lpBuffer full if opts == false, there will be no blocking

Parameters:

  • (Hash)
  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :hConsoleInput (Integer)
  • :lpBuffer (PINPUT_RECORD || Array)
  • :nLength (Integer)
  • :lpNumberOfEventsRead (Integer)

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vigilem/win32_api/rubyized.rb', line 39

def read_console_input(opts={})
  _options(opts)
  
  lp_buffer = []
  
  if (default = (blocking = opts[:blocking]).nil?) or blocking
    begin
      win32_api_rubyized_src.ReadConsoleInput(opts[:hConsoleInput], opts[:lpBuffer], opts[:nLength], opts[:lpNumberOfEventsRead])
      lp_buffer += opts[:lpBuffer]
    end while (not default) and lp_buffer.size < opts[:nLength]
    opts[:lpBuffer].replace(lp_buffer)
  elsif not peek_console_input.empty?
    win32_api_rubyized_src.ReadConsoleInput(opts[:hConsoleInput], opts[:lpBuffer], opts[:nLength], opts[:lpNumberOfEventsRead])
    opts[:lpBuffer]
  end
end