Module VirtualKeys
#1
Module VirtualKeys
Version: 1.1

Introduction
In addition to enabling all keys for use in RPGMaker is also accompanied by methods that have helped in the use of keys, some try copy existing methods in the module Input, and other totally new or enhanced.

Features
  • method #press?
  • method #trigger?
  • method #repeat?
  • method #dir4 with modify
  • method #dir8 with modify
  • method for to use GetKeyState and GetAsyncKeyState functions, used on the other methods
  • method #get_char that returns the pressed key(follow ABNT rules)
  • all features previously were maked on a separete module, because this they are totaly independents of Input module.
  • dont need update the module such in Input module.

Screenshots
Not need.

Demo
RMXP


Script
Code:
#========================================
# Module VirtualKeys
#----------------------------------------
#by:      zecomeia
#date:    28/02/2010
#for:     RGSS & RGSS2
#version: 1.1
#www.colmeia-do-ze.blogspot.com
#----------------------------------------
=begin

*NOTE: recommended don't update the inputs using Input.update
on the main loop of the scene to use functions of the script.
para evitar conflitos, for to avoid conflicts.

Module Methods:
------------------------------------------------------------
VirtualKeys#press?(key)

Determines whether the button num is currently being
pressed.
If the button is being pressed, returns TRUE. If not,
returns FALSE.
-------------------------------------------------------------
VirtualKeys#trigger?(key)

Determines whether the button "key" is being pressed again.
"Pressed again" is seen as time having passed between the
button being not pressed and being pressed.
If the button is being pressed, returns TRUE. If not,
returns FALSE.
------------------------------------------------------------
VirtualKeys#repeat?(key)

Determines whether the button "key" is being pressed again.
Unlike trigger?, takes into account the repeat input of a
button being held down continuously.
If the button is being pressed, returns TRUE. If not,
returns FALSE.
------------------------------------------------------------
VirtualKeys#dir4(type=0, ignore_numpad=false)

Checks the status of the directional buttons, translates the
data into a specialized 4-direction input format, and returns
the number pad equivalent (2, 4, 6, 8).
If no directional buttons are being pressed (or the equivalent),
returns 0.

Arguments

type: defines the method that will evaluate the inputs
(#press?(key) or #trigger?(key)).
0=#press?(key)
1=#trigger?(key)

ignore_numpad: if true ignore inputs of the numpad, else don't.
-------------------------------------------------------------
VirtualKeys#dir8(type=0, ignore_numpad=false)

Checks the status of the directional buttons, translates the
data into a specialized 8-direction input format, and returns
the number pad equivalent (1, 2, 3, 4, 6, 7, 8, 9).
If no directional buttons are being pressed (or the equivalent),
returns 0.

Arguments

type: defines the method that will evaluate the inputs
(#press?(key) or #trigger?(key)).
0=#press?(key)
1=#trigger?(key)

ignore_numpad: if true ignore inputs of the numpad, else don't.
-------------------------------------------------------------
VirtualKeys#get_char()

Returns the character in a array corresponding to the
pressed key.
*Keys corresponding to the accents ( ' `^ ¨ ~ ) return 1 size
array with true and change the value of the variable "$Acento"
with a corresponding number on the first click.The second
click, the method returns an 2 size array with the accents.
~: $Acento=1
^: $Acento=2
´: $Acento=3
`: $Acento=4
¨: $Acento=5
Else
$Acento=0

*NOTE: to ABNT.
*NOTE: all characters and "symbols"(@ # $ %...) returned as
string objects within the array.
*NOTE: numpad numbers are returned as string objects within
the array, while the other numbers are returned in the array
as objects of type integer.
-------------------------------------------------------------

*"key" should be replaced by a constant of module "VirtualKeys"
*See the constants in module "VirtualKeys"

Sample:
if VirtualKeys.trigger?(VirtualKeys::VK_A)
  print "\"A\" is being pressed"
end
=end

module VirtualKeys
GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",'i','i')
GetKeyState = Win32API.new("user32","GetKeyState",'i','i')
$LastKey=0
$CallsCounter=0
$Acento=0

#Constants copied:
#http://msdn.microsoft.com/en-us/library/ms927178.aspx
#http://www.kbdedit.com/manual/low_level_vk_list.html

VK_LBUTTON=0x01 #Left mouse button
VK_RBUTTON=0x02 #Right mouse button
VK_CANCEL=0x03 #Control-break processing
VK_MBUTTON=0x04 #Middle mouse button on a three-button mouse
VK_BACK=0x08 #BACKSPACE key
VK_TAB=0x09 #TAB key
VK_CLEAR=0x0C #CLEAR key
VK_RETURN=0x0D #ENTER key
VK_SHIFT=0x10 #SHIFT key
VK_CONTROL=0x11 #CTRL key
VK_MENU=0x12 #ALT key
VK_PAUSE=0x13 #PAUSE key
VK_CAPITAL=0x14 #CAPS LOCK key
VK_ESCAPE=0x1B #ESC key
VK_SPACE=0x20 #SPACEBAR
VK_PRIOR=0x21 #PAGE UP key
VK_NEXT=0x22 #PAGE DOWN key
VK_END=0x23 #END key
VK_HOME=0x24 #HOME key
VK_LEFT=0x25 #LEFT ARROW key
VK_UP=0x26 #UP ARROW key
VK_RIGHT=0x27 #RIGHT ARROW key
VK_DOWN=0x28 #DOWN ARROW key
VK_SELECT=0x29 #SELECT key
VK_EXECUTE=0x2B #EXECUTE key
VK_SNAPSHOT=0x2C #PRINT SCREEN key
VK_INSERT=0x2D #INS key
VK_DELETE=0x2E #DEL key
VK_HELP=0x2F #HELP key

VK_0=0x30 #0 key
VK_1=0x31 #1 key
VK_2=0x32 #2 key
VK_3=0x33 #3 key
VK_4=0x34 #4 key
VK_5=0x35 #5 key
VK_6=0x36 #6 key
VK_7=0x37 #7 key
VK_8=0x38 #8 key
VK_9=0x39 #9 key

VK_A=0x41 #A key
VK_B=0x42 #B key
VK_C=0x43 #C key
VK_D=0x44 #D key
VK_E=0x45 #E key
VK_F=0x46 #F key
VK_G=0x47 #G key
VK_H=0x48 #H key
VK_I=0x49 #I key
VK_J=0x4A #J key
VK_K=0x4B #K key
VK_L=0x4C #L key
VK_M=0x4D #M key
VK_N=0x4E #N key
VK_O=0x4F #O key
VK_P=0x50 #P key
VK_Q=0x51 #Q key
VK_R=0x52 #R key
VK_S=0x53 #S key
VK_T=0x54 #T key
VK_U=0x55 #U key
VK_V=0x56 #V key
VK_W=0x57 #W key
VK_X=0x58 #X key
VK_Y=0x59 #Y key
VK_Z=0x5A #Z key

VK_LWIN=0x5B #Left Windows key on a Microsoft Natural Keyboard
VK_RWIN=0x5C #Right Windows key on a Microsoft Natural Keyboard
VK_APPS=0x5D #Applications key on a Microsoft Natural Keyboard
VK_NUMPAD0=0x60 #Numeric keypad 0 key
VK_NUMPAD1=0x61 #Numeric keypad 1 key
VK_NUMPAD2=0x62 #Numeric keypad 2 key
VK_NUMPAD3=0x63 #Numeric keypad 3 key
VK_NUMPAD4=0x64 #Numeric keypad 4 key
VK_NUMPAD5=0x65 #Numeric keypad 5 key
VK_NUMPAD6=0x66 #Numeric keypad 6 key
VK_NUMPAD7=0x67 #Numeric keypad 7 key
VK_NUMPAD8=0x68 #Numeric keypad 8 key
VK_NUMPAD9=0x69 #Numeric keypad 9 key
VK_MULTIPLY=0x6A #Multiply key
VK_ADD=0x6B #Add key
VK_SEPARATOR=0x6C #Separator key
VK_SUBTRACT=0x6D #Subtract key
VK_DECIMAL=0x6E #Decimal key
VK_DIVIDE=0x6F #Divide key
VK_F1=0x70 #F1 key
VK_F2=0x71 #F2 key
VK_F3=0x72 #F3 key
VK_F4=0x73 #F4 key
VK_F5=0x74 #F5 key
VK_F6=0x75 #F6 key
VK_F7=0x76 #F7 key
VK_F8=0x77 #F8 key
VK_F9=0x78 #F9 key
VK_F10=0x79 #F10 key
VK_F11=0x7A #F11 key
VK_F12=0x7B #F12 key
VK_F13=0x7C #F13 key
VK_F14=0x7D #F14 key
VK_F15=0x7E #F15 key
VK_F16=0x7F #F16 key
VK_F17=0x80 #F17 key
VK_F18=0x81 #F18 key
VK_F19=0x82 #F19 key
VK_F20=0x83 #F20 key
VK_F21=0x84 #F21 key
VK_F22=0x85 #F22 key (PPC only) Key used to lock device.
VK_F23=0x86 #F23 key
VK_F24=0x87 #F24 key
VK_NUMLOCK=0x90 #NUM LOCK key
VK_SCROLL=0x91 #SCROLL LOCK key
VK_LSHIFT=0xA0 #Left SHIFT
VK_RSHIFT=0xA1 #Right SHIFT
VK_LCONTROL=0xA2 #Left CTRL
VK_RCONTROL=0xA3 #Right CTRL
VK_LMENU=0xA4 #Left ALT
VK_RMENU=0xA5 #Right ALT
VK_PACKET=0xE7 #Used to pass Unicode characters as if they were keystrokes.
#If VK_PACKET is used with SendInput, ; the Unicode character to be delivered
#should be placed into the lower 16 bits of the scan code. If a keyboard message
#is removed from the message queue and the virtual key is VK_PACKET, ; the
#Unicode character will be the upper 16 bits of the lparam.
VK_ATTN=0xF6 #ATTN key
VK_CRSEL=0xF7 #CRSEL key
VK_EXSEL=0xF8 #EXSEL key
VK_EREOF=0xF9 #Erase EOF key
VK_PLAY=0xFA #PLAY key
VK_ZOOM=0xFB #ZOOM key
VK_NONAME=0xFC #Reserved for future use
VK_PA1=0xFD #PA1 key
VK_OEM_CLEAR=0xFE #CLEAR key
VK_KEYLOCK=0xF22 #Key used to lock device

VK_OEM_SCROLL=0x91 #None
VK_OEM_1=0xBA #";:" for US --- "ç" no padrão ABNT
VK_OEM_PLUS=0xBB #"+" any country/region
VK_OEM_COMMA=0xBC #"," any country/region
VK_OEM_MINUS=0xBD #"-" any country/region
VK_OEM_PERIOD=0xBE #"." any country/region
VK_OEM_2=0xBF #"/?" for US --- ";:" no padrão ABNT
VK_OEM_3=0xC0 #"`~" for US --- " '" " no padrão ABNT
VK_OEM_4=0xDB #"[{" for US --- "´`" no padrão ABNT
VK_OEM_5=0xDC #"\|" for US --- "]" no padrão ABNT
VK_OEM_6=0xDD #"]}" for US --- "[" no padrão ABNT
VK_OEM_7=0xDE #"'"" for US --- "~^" no padrão ABNT
VK_OEM_8=0xDF #None
VK_OEM_AX=0xE1 #AX key on Japanese AX keyboard
VK_OEM_102=0xE2 #"<>" or "\|" on RT 102-key keyboard --- "\|" no padrão ABNT
VK_ABNT_C1 = 0xC1 #"?/°" no padrão ABNT
VK_ABNT_C2 = 0xC2 #"." no padrão ABNT

VK_DBE_ALPHANUMERIC=0x0f0 #Changes the mode to alphanumeric.
VK_DBE_KATAKANA=0x0f1 #Changes the mode to Katakana.
VK_DBE_HIRAGANA=0x0f2 #Changes the mode to Hiragana.
VK_DBE_SBCSCHAR=0x0f3 #Changes the mode to single-byte characters.
VK_DBE_DBCSCHAR=0x0f4 #Changes the mode to double-byte characters.
VK_DBE_ROMAN=0x0f5 #Changes the mode to Roman characters.
VK_DBE_NOROMAN=0x0f6 #Changes the mode to non-Roman characters.
VK_DBE_ENTERWORDREGISTERMODE=0x0f7 #Activates the word registration dialog box.
VK_DBE_ENTERIMECONFIGMODE=0x0f8 #Activates a dialog box for setting up an IME environment.
VK_DBE_FLUSHSTRING=0x0f9 #Deletes the undetermined string without determining it.
VK_DBE_CODEINPUT=0x0fa #Changes the mode to code input.
VK_DBE_NOCODEINPUT=0x0fb #Changes the mode to no-code input.

  #===========================
  # GetAsyncKeyState function
  #===========================
  def self.gaks(key)
    GetAsyncKeyState.call(key)
  end

  #======================
  # GetKeyState function
  #======================
  def self.gks(key)
    GetKeyState.call(key)
  end

  #============================================================
  # VirtualKeys#press?(key)
  #============================================================
  def self.press?(key)
    getState = self.gaks(key)
    return(true) if getState != 0
    false
  end

  #============================================================
  # VirtualKeys#trigger?(key)
  #============================================================
  def self.trigger?(key)
    getState = self.gaks(key)
    getState2 = 0
    getState2 = self.gaks($LastKey) if $LastKey != 0
    return($LastKey = 0;false) if getState == 0 and getState2 == 0
    return(false) if key == $LastKey and getState != 0
    $LastKey = key if getState != 0
    return false if getState == 0
    true
  end

  #============================================================
  # VirtualKeys#repeat?(key)
  #============================================================
  def self.repeat?(key)
    return ($CallsCounter -= 1;false) if $CallsCounter > 0
    ($CallsCounter = 5;return(true)) if self.gaks(key) != 0
    false
  end

  #============================================================
  # VirtualKeys#dir4(type=0, ignore_numpad=false)
  #============================================================
  def self.dir4(type=0,ignore_numpad=false)
    case type
    when 0
      if self.press?(VK_DOWN) or (!ignore_numpad && self.press?(VK_NUMPAD2)) ; return(2)
      elsif self.press?(VK_LEFT) or (!ignore_numpad && self.press?(VK_NUMPAD4)) ; return(4)
      elsif self.press?(VK_RIGHT) or (!ignore_numpad && self.press?(VK_NUMPAD6)) ; return(6)
      elsif self.press?(VK_UP) or (!ignore_numpad && self.press?(VK_NUMPAD8)) ; return(8)
      end
    when 1
      if self.trigger?(VK_DOWN) or (!ignore_numpad && self.trigger?(VK_NUMPAD2)) ; return(2)
      elsif self.trigger?(VK_LEFT) or (!ignore_numpad && self.trigger?(VK_NUMPAD4)) ; return(4)
      elsif self.trigger?(VK_RIGHT) or (!ignore_numpad && self.trigger?(VK_NUMPAD6)) ; return(6)
      elsif self.trigger?(VK_UP) or (!ignore_numpad && self.trigger?(VK_NUMPAD8)) ; return(8)
      end
    end
    0
  end

  #============================================================
  # VirtualKeys#dir8(type=0, ignore_numpad=false)
  #============================================================
  def self.dir8(type=0,ignore_numpad=false)
    case type
    when 0
      if (self.press?(VK_DOWN) && self.press?(VK_LEFT)) or \
        (!ignore_numpad && (self.press?(VK_NUMPAD2) && self.press?(VK_NUMPAD4))) ; return(1)
      elsif (self.press?(VK_DOWN) && self.press?(VK_RIGHT)) or \
        (!ignore_numpad && (self.press?(VK_NUMPAD2) && self.press?(VK_NUMPAD6))) ; return(3)
      elsif (self.press?(VK_UP) && self.press?(VK_LEFT)) or \
        (!ignore_numpad && (self.press?(VK_NUMPAD8) && self.press?(VK_NUMPAD4))) ; return(7)
      elsif (self.press?(VK_UP) && self.press?(VK_RIGHT)) or \
        (!ignore_numpad && (self.press?(VK_NUMPAD2) && self.press?(VK_NUMPAD6))) ; return(9)
      end
    when 1
      if (self.trigger?(VK_DOWN) && self.trigger?(VK_LEFT)) or \
        (!ignore_numpad && (self.trigger?(VK_NUMPAD2) && self.trigger?(VK_NUMPAD4))) ; return(1)
      elsif (self.trigger?(VK_DOWN) && self.trigger?(VK_RIGHT)) or \
        (!ignore_numpad && (self.trigger?(VK_NUMPAD2) && self.trigger?(VK_NUMPAD6))) ; return(3)
      elsif (self.trigger?(VK_UP) && self.trigger?(VK_LEFT)) or \
        (!ignore_numpad && (self.trigger?(VK_NUMPAD8) && self.trigger?(VK_NUMPAD4))) ; return(7)
      elsif (self.trigger?(VK_UP) && self.trigger?(VK_RIGHT)) or \
        (!ignore_numpad && (self.trigger?(VK_NUMPAD2) && self.trigger?(VK_NUMPAD6))) ; return(9)
      end
    end
    self.dir4(type,ignore_numpad)
  end

if self.gks(VK_CAPITAL) == 0
  $CAPITAL = false
else $CAPITAL = true
end

  #============================================================
  # VirtualKeys#get_char()
  #============================================================
  def self.get_char()
    if self.gaks(VK_SPACE) != 0
      char = ' '
    end
    if self.gaks(VK_OEM_7) != 0
      case $Acento
      when 0
        $Acento = 1
        $Acento = 2 if self.gaks(VK_SHIFT) != 0
        return([true])
      when 1
        char = "~"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 2
        char = "^"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 3
        char = "´"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 4
        char = "`"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 5
        char = "¨"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      end
      $Acento = 0 ; return(char)
    elsif self.gaks(VK_OEM_4) != 0
      case $Acento
      when 0
        $Acento = 3
        $Acento = 4 if self.gaks(VK_SHIFT) != 0
        return([true])
      when 1
        char = "~"
        c = "´"
        c = "`" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 2
        char = "^"
        c = "´"
        c = "`" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 3
        char = "´"
        c = "´"
        c = "`" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 4
        char = "`"
        c = "´"
        c = "`" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      when 5
        char="¨"
        c = "~"
        c = "^" if self.gaks(VK_SHIFT) != 0
        char = [char,c]
      end
      $Acento = 0 ; return(char)
    elsif self.gaks(VK_6) != 0 and self.gaks(VK_SHIFT) != 0
      case $Acento
      when 0
        $Acento = 5
        return([true])
      when 1
        char = "~"
        c = "¨"
        char = [char,c]
      when 2
        char = "^"
        c = "¨"
        char = [char,c]
      when 3
        char = "´"
        c = "¨"
        char = [char,c]
      when 4
        char = "`"
        c = "¨"
        char = [char,c]
      when 5
        char = "¨"
        c = "¨"
        char = [char,c]
      end
      $Acento = 0 ; return(char)
    end
    if self.gks(VK_CAPITAL) == 0
      $CAPITAL = false
    else $CAPITAL = true end
    if self.gaks(VK_A) != 0 ; char = 'a'
    elsif self.gaks(VK_B) != 0 ; char = 'b'
    elsif self.gaks(VK_C) != 0 ; char = 'c'
    elsif self.gaks(VK_D) != 0 ; char = 'd'
    elsif self.gaks(VK_E) != 0 ; char = 'e'
    elsif self.gaks(VK_F) != 0 ; char = 'f'
    elsif self.gaks(VK_G) != 0 ; char = 'g'
    elsif self.gaks(VK_H) != 0 ; char = 'h'
    elsif self.gaks(VK_I) != 0 ; char = 'i'
    elsif self.gaks(VK_J) != 0 ; char = 'j'
    elsif self.gaks(VK_K) != 0 ; char = 'k'
    elsif self.gaks(VK_L) != 0 ; char = 'l'
    elsif self.gaks(VK_M) != 0 ; char = 'm'
    elsif self.gaks(VK_N) != 0 ; char = 'n'
    elsif self.gaks(VK_O) != 0 ; char = 'o'
    elsif self.gaks(VK_P) != 0 ; char = 'p'
    elsif self.gaks(VK_Q) != 0 ; char = 'q'
    elsif self.gaks(VK_R) != 0 ; char = 'r'
    elsif self.gaks(VK_S) != 0 ; char = 's'
    elsif self.gaks(VK_T) != 0 ; char = 't'
    elsif self.gaks(VK_U) != 0 ; char = 'u'
    elsif self.gaks(VK_V) != 0 ; char = 'v'
    elsif self.gaks(VK_W) != 0 ; char = 'w'
    elsif self.gaks(VK_X) != 0 ; char = 'x'   
    elsif self.gaks(VK_Y) != 0 ; char = 'y'
    elsif self.gaks(VK_Z) != 0 ; char = 'z'
    elsif self.gaks(VK_OEM_1) != 0 ; char = 'ç'
    elsif (self.gaks(VK_0)!=0) ; char = 0
    elsif (self.gaks(VK_1)!=0) ; char = 1
    elsif (self.gaks(VK_2)!=0) ; char = 2
    elsif (self.gaks(VK_3)!=0) ; char = 3
    elsif (self.gaks(VK_4)!=0) ; char = 4
    elsif (self.gaks(VK_5)!=0) ; char = 5
    elsif (self.gaks(VK_6)!=0) ; char = 6
    elsif (self.gaks(VK_7)!=0) ; char = 7
    elsif (self.gaks(VK_8)!=0) ; char = 8
    elsif (self.gaks(VK_9)!=0) ; char = 9
    elsif (self.gaks(VK_NUMPAD0)!=0) ; char = '0'
    elsif (self.gaks(VK_NUMPAD1)!=0) ; char = '1'
    elsif (self.gaks(VK_NUMPAD2)!=0) ; char = '2'
    elsif (self.gaks(VK_NUMPAD3)!=0) ; char = '3'
    elsif (self.gaks(VK_NUMPAD4)!=0) ; char = '4'
    elsif (self.gaks(VK_NUMPAD5)!=0) ; char = '5'
    elsif (self.gaks(VK_NUMPAD6)!=0) ; char = '6'
    elsif (self.gaks(VK_NUMPAD7)!=0) ; char = '7'
    elsif (self.gaks(VK_NUMPAD8)!=0) ; char = '8'
    elsif (self.gaks(VK_NUMPAD9)!=0) ; char = '9'     
    elsif (self.gaks(VK_OEM_COMMA)!=0) or (self.gaks(VK_DECIMAL)!=0) ; char = ','
    elsif self.gaks(VK_OEM_PERIOD) != 0 ; char = '.'   
    elsif self.gaks(VK_OEM_PLUS) != 0 ; char = '='
    elsif (self.gaks(VK_OEM_MINUS)!=0) or (self.gaks(VK_SUBTRACT)!=0) ; char = '-'
    elsif self.gaks(VK_ABNT_C2) != 0 ; return (['.'])
    elsif self.gaks(VK_ADD) != 0 ; return (['+'])
    elsif self.gaks(VK_DIVIDE) != 0 ; return (['/'])   
    elsif self.gaks(VK_MULTIPLY) != 0 ; return (['*'])
    elsif self.gaks(VK_ABNT_C1) != 0 ; char = '/'
    elsif self.gaks(VK_OEM_102) != 0 ; char = "\\"
    elsif self.gaks(VK_OEM_2) != 0 ; char = ";"
    elsif self.gaks(VK_OEM_3) != 0 ; char = "\'"
    elsif self.gaks(VK_OEM_5) != 0 ; char = ']'
    elsif self.gaks(VK_OEM_6) != 0 ; char = '['
    end
    if self.gaks(VK_SHIFT) != 0 and char != nil and char.is_a?(Integer) == false
      case char
      when ',' ;  char = '<'
      when '.' ;  char = '>'
      when '=' ;  char = '+'
      when '-' ;  char = '_'
      when "\\" ; char = '|'
      when ';' ;  char = ':'
      when '/' ;  char = '?'
      when "\'" ; char = "\""
      when ']' ;  char = '}'
      when '[' ;  char = '{'
      end
    end
    if (self.gaks(VK_SHIFT) != 0 or $CAPITAL == true) and char != nil and \
      char.is_a?(Integer) == false
      char=char.upcase
      char='Ç' if char=='ç'
    end
    if self.gaks(VK_SHIFT) != 0 and char != nil and char.is_a?(Integer) == true
      case char
      when 0 ; char = ')'
      when 1 ; char = '!'
      when 2 ; char = '@'
      when 3 ; char = '#'
      when 4 ; char = '$'
      when 5 ; char = '%'
      when 7 ; char = '&'
      when 8 ; char = '*'
      when 9 ; char = '('
      end
    end
    if self.gaks(VK_MENU) != 0 and char != nil and char.is_a?(Integer) == true
      case char
      when 1 ; char = '¹'
      when 2 ; char = '²'
      when 3 ; char = '³'
      when 4 ; char = '£'
      when 5 ; char = '¢'
      when 6 ; char = '¬'     
      end
    end
    if self.gaks(VK_MENU) != 0 and char != nil and char.is_a?(Integer) == false
      case char
      when '/' ; char = '°'
      when ']' ; char = 'º'
      when '[' ; char = 'ª'
      when '=' ; char = '§'
      end
    end
    if $Acento != 0 and char == ' '
      case $Acento
      when 1 ; char = '~'
      when 2 ; char = '^'
      when 3 ; char = '´'
      when 4 ; char = '`'
      when 5 ; char = '¨'
      end
      $Acento = 0
    end
    if $Acento != 0 and char =~ /[\w]/i
      case $Acento
      when 1
        if char == 'A' ; char = 'Ã'
        elsif char == 'a' ; char = 'ã'
        elsif char == 'O' ; char = 'Õ'
        elsif char == 'o' ; char = 'õ'
        elsif char == 'N' ; char = 'Ñ'
        elsif char == 'n' ; char = 'ñ'
        end
      when 2
        if char == 'A' ; char = 'Â'
        elsif char == 'a' ; char = 'â'
        elsif char == 'E' ; char = 'Ê'
        elsif char == 'e' ; char = 'ê'
        elsif char == 'I' ; char = 'Î'
        elsif char == 'i' ; char = 'î'
        elsif char == 'O' ; char = 'Ô'
        elsif char == 'o' ; char = 'ô'
        elsif char == 'U' ; char = 'Û'
        elsif char == 'u' ; char = 'û'
        end
      when 3
        if char == 'A' ; char = 'Á'
        elsif char == 'a' ; char = 'á'
        elsif char == 'E' ; char = 'É'
        elsif char == 'e' ; char = 'é'
        elsif char == 'I' ; char = 'Í'
        elsif char == 'i' ; char = 'í'
        elsif char == 'O' ; char = 'Ó'
        elsif char == 'o' ; char = 'ó'
        elsif char == 'U' ; char = 'Ú'
        elsif char == 'u' ; char = 'ú'
        end
      when 4
        if char == 'A' ; char = 'À'
        elsif char == 'a' ; char = 'Ã '
        elsif char == 'E' ; char = 'È'
        elsif char == 'e' ; char = 'è'
        elsif char == 'I' ; char = 'Ì'
        elsif char == 'i' ; char = 'ì'
        elsif char == 'O' ; char = 'Ò'
        elsif char == 'o' ; char = 'ò'
        elsif char == 'U' ; char = 'Ù'
        elsif char == 'u' ; char = 'ù'
        end
      when 5
        if char == 'A' ; char = 'Ä'
        elsif char == 'a' ; char = 'ä'
        elsif char == 'E' ; char = 'Ë'
        elsif char == 'e' ; char = 'ë'
        elsif char == 'I' ; char = 'Ï'
        elsif char == 'i' ; char = 'ï'
        elsif char == 'O' ; char = 'Ö'
        elsif char == 'o' ; char = 'ö'
        elsif char == 'U' ; char = 'Ü'
        elsif char == 'u' ; char = 'ü'
        end
      end
      $Acento = 0
    elsif $Acento != 0 and char != nil
      case $Acento
      when 1 ; char = ['~',char]
      when 2 ; char = ['^',char]
      when 3 ; char = ['´',char]
      when 4 ; char = ['`',char]
      end
      $Acento = 0
      return(char)
    end
    [char]
  end

end

Instructions

Install the script up of any script that use it.

For use the methods of verify #press?, #trigger?, #repeat? follow the sample:

Code:
if VirtualKeys.press?(Virtual::VK_T)
print 'pressed T''
end

*The argument is integer, corresponding with the VirtualKeys list on the begin os module with all contants defineds.

See an example of method #get_char :

Code:
char = VirtualKeys.get_char()
if char[0] == true or char.size == 2 # if accent...
case $Acento
when 1 ; print "pressed ~"
when 2 ; print "pressed ^"
when 3 ; print "pressed ´"
when 4 ; print "pressed  `"
when 5 ; print "pressed ¨"
end
elsif char[0] != nil #iy another character...
print "pressed #{char[0]}"
end


The methods #dir4 and #dir8 have the single operation, but #dir4 verify only 4 directions and #dir8 verify combinations between directions if not opposite. No news yet. But on the VirtualKeys module 2 new input parameters appear, "type" and "ignore_numpad". The first can have 2 values: 0=#press? or 1=#trigger?. This change the method used for verify the moviment keys. The argument "ignore_numpad" when true, not verify if the moviment keys  on numpad(1,2,3,4,6,7,8 e 9). Example:

Code:
case VirtualKeys.dir8(1,true)
when 1 ; print('down left')
when 2 ; print('down')
when 3 ; print('down right')
when 4 ; print('left')
when 6 ; print('right')
when 7 ; print('up left')
when 8 ; print('up')
when 9 ; print('up right')
end

*Deafault values for the parameters are (0,false).

The methods that call GetKeyState and GetAsyncKeyState functions are, #gks and #gaks.  #gks verify the key state, where ever pressed switches between zero or non-zero(sample: CAPS LOCK), already #gaks verify if key have been pressed. Both, when key's state is ON returns zero, else(when OFF) returns non-zero.

FAQ
No questions yet

Compatibility
When use this script's functions on a scene, try no use update method of Input module in main loop of scene, to avoid conflicts or bad performace of this script.

Credits and Thanks
by zecomeia
got constants of sites:
http://msdn.microsoft.com/en-us/library/ms927178.aspx
http://www.kbdedit.com/manual/low_level_vk_list.html

Terms and Conditions
[Image: 88x31.png]

Scripts RGSS, Resources, Tutorials and Translations by zecomeia is licensed under a
Creative Commons Atribuição-Uso Não-Comercial-Compartilhamento pela mesma Licença 2.5 Brasil License.
Permissions beyond the scope of this license may be available at Santuário RPG Maker
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Audio Module Rewrite mcisendstring DerVVulfman 25 41,534 05-03-2020, 08:08 PM
Last Post: MikiIsAway
   NRGSS Module Function Library Narzew 2 8,229 05-12-2012, 11:07 AM
Last Post: Narzew
   JEM: Jennifer's Entry Module DerVVulfman 0 5,497 10-14-2010, 04:30 AM
Last Post: DerVVulfman
   Profession/Offices Module EX-PLUS! Mephistox 0 5,024 03-07-2008, 06:54 AM
Last Post: Mephistox
   Keyboard Input Module (Revised) Near Fantastica 0 4,938 03-02-2008, 07:40 AM
Last Post: Near Fantastica
   Geometry Module Trickster 0 4,291 03-02-2008, 05:52 AM
Last Post: Trickster



Users browsing this thread: 1 Guest(s)