Introduction:
Hello, on Thursday(October 11, 2011) I wanted to practice a little more of using ruby variables on C, so I've done this Input System, it's made of four scripts:
This Input is an Add-On for Enterbrain's Input, it doesn't remove or substitute any Enterbrain's methods, only add news methods.
Why should you use this?: Because it is fast and gets all the needed variables in only one Win32API command.
Scripts (in English):
Simple Input
Virtual-Key Codes
Check Keys
Window_Edit
DLL Source:
Demo (in Portuguese):
Download using DROPBOX.COM
Compiled DLL included in Demo. Not tested yet on RMVX.
As you seen this is a simple and common script, that's why I'll only makes update when it's necessary; anyway thanks for the interesting on it. 😀
Hello, on Thursday(October 11, 2011) I wanted to practice a little more of using ruby variables on C, so I've done this Input System, it's made of four scripts:
- Simple Input - A Input class that uses C++ to get all the keys pressed, mouse position, and some joystick buttons.
- Virtual-Key Codes - A conversion of Microsoft Virtual Key List for Ruby.
- Check Keys - A function that converts one key pressed into a char. (if needed, I convert it to C too)
- Window_Edit - A Window to input some information, it has: a cursor, functions for the keys home, end, delete, left, right, and ctr+v if you have Aleworks library(this last function wasn't tested yet).
This Input is an Add-On for Enterbrain's Input, it doesn't remove or substitute any Enterbrain's methods, only add news methods.
Why should you use this?: Because it is fast and gets all the needed variables in only one Win32API command.
Scripts (in English):
Simple Input
- #==============================================================================
- # Name: Simple Input
- # Description: Add news methods to get any keyboard key, mouse position, and joysticks buttons
- #------------------------------------------------------------------------------
- # Developed by: PedroHLC
- # Version: 1.0
- #==============================================================================
- Graphics.update
- $hWnd = Win32API.new('user32', 'GetActiveWindow', '', 'L').call
- module Input
- @key = Array.new(256, false)
- @old_key = Array.new(256, false)
- @state = Array.new(3, false)
- @joystick = [0, 0, 0, 0] #Buttons, X, Y, POV
- @mousepos = [0, 0] #x, y
- @cursor = Sprite.new
- @cursor.z = 99999
- @cursor.bitmap = RPG::Cache.icon('001-Weapon01')
- @cursor_hide = false
- GETINPUT = Win32API.new('Input.dll', 'getInput', 'llllll', 'i')
- class << self
- alias enterbrain_update update
- end
- module_function
- def update
- GETINPUT.call(@key.__id__, @old_key.__id__, @state.__id__,
- @joystick.__id__, @mousepos.__id__, $hWnd)
- enterbrain_update
- if @cursor.visible = (!@cursor_hide)
- @cursor.x = @mousepos[0]
- @cursor.y = @mousepos[1]
- end
- end
- def getLockKeyState(key)
- case key
- when 0x14
- return @state[0]
- when 0x90
- return @state[1]
- when 0x91
- return @state[2]
- end
- return false
- end
- def getKeyState(key)
- return @key[key]
- end
- def getLastKeyState(key)
- return @old_key[key]
- end
- def getKeyPressed(key)
- return (@key[key] and !@old_key[key])
- end
- def getMousePos
- return @mousepos
- end
- def getJoystickButtons
- return (@joystick[0].nil? ? @joystick[0] : 0)
- end
- def setCursorHide(value)
- @cursor_hide = value
- end
- def setCursorBitmap(value)
- @cursor.bitmap = value
- end
- def isUpperingCase
- return ( getKeyState(VK::SHIFT) | getLockKeyState(VK::CAPITAL) )
- end
- end
Expand to see the code.
Virtual-Key Codes
- #==========================================================================
- # Name: Virtual-Key Codes
- # Description: List with keyboard keys codes (versão MSDN)
- #--------------------------------------------------------------------------
- # By: msdn.microsoft.com
- # Ripped by: PedroHLC
- # Last update: 11/10/10 - 22:00
- # Original state:
- # http://msdn.microsoft.com/en-us/library ... 85%29.aspx
- #==========================================================================
- module VK
- LBUTTON = 0x01 #Left mouse button
- RBUTTON = 0x02 #Right mouse button
- CANCEL = 0x03 #Control-break processing
- MBUTTON = 0x04 #Middle mouse button (three-button mouse)
- XBUTTON1 = 0x05 #X1 mouse button
- XBUTTON2 = 0x06 #X2 mouse button
- BACK = 0x08 #BACKSPACE key
- TAB = 0x09 #TAB key
- CLEAR = 0x0C #CLEAR key
- RETURN = 0x0D #ENTER key
- SHIFT = 0x10 #SHIFT key
- CONTROL = 0x11 #CTRL key
- MENU = 0x12 #ALT key
- PAUSE = 0x13 #PAUSE key
- CAPITAL = 0x14 #CAPS LOCK key
- KANA = 0x15 #IME Kana mode
- HANGUEL = 0x15 #IME Hanguel mode (maintained for compatibility; use HANGUL)
- HANGUL = 0x15 #IME Hangul mode
- JUNJA = 0x17 #IME Junja mode
- FINAL = 0x18 #IME final mode
- HANJA = 0x19 #IME Hanja mode
- KANJI = 0x19 #IME Kanji mode
- ESCAPE = 0x1B #ESC key
- CONVERT = 0x1C #IME convert
- NONCONVERT = 0x1D #IME nonconvert
- ACCEPT = 0x1E #IME accept
- MODECHANGE = 0x1F #IME mode change request
- SPACE = 0x20 #SPACEBAR
- PRIOR = 0x21 #PAGE UP key
- NEXT = 0x22 #PAGE DOWN key
- KEND = 0x23 #END key
- HOME = 0x24 #HOME key
- LEFT = 0x25 #LEFT ARROW key
- UP = 0x26 #UP ARROW key
- RIGHT = 0x27 #RIGHT ARROW key
- DOWN = 0x28 #DOWN ARROW key
- SELECT = 0x29 #SELECT key
- PRINT = 0x2A #PRINT key
- EXECUTE = 0x2B #EXECUTE key
- SNAPSHOT = 0x2C #PRINT SCREEN key
- INSERT = 0x2D #INS key
- DELETE = 0x2E #DEL key
- HELP = 0x2F #HELP key
- KEY_0 = 0x30 #0 key
- KEY_1 = 0x31 #1 key
- KEY_2 = 0x32 #2 key
- KEY_3 = 0x33 #3 key
- KEY_4 = 0x34 #4 key
- KEY_5 = 0x35 #5 key
- KEY_6 = 0x36 #6 key
- KEY_7 = 0x37 #7 key
- KEY_8 = 0x38 #8 key
- KEY_9 = 0x39 #9 key
- A = 0x41 #A key
- B = 0x42 #B key
- C = 0x43 #C key
- D = 0x44 #D key
- E = 0x45 #E key
- F = 0x46 #F key
- G = 0x47 #G key
- H = 0x48 #H key
- I = 0x49 #I key
- J = 0x4A #J key
- K = 0x4B #K key
- L = 0x4C #L key
- M = 0x4D #M key
- N = 0x4E #N key
- O = 0x4F #O key
- P = 0x50 #P key
- Q = 0x51 #Q key
- R = 0x52 #R key
- S = 0x53 #S key
- T = 0x54 #T key
- U = 0x55 #U key
- V = 0x56 #V key
- W = 0x57 #W key
- X = 0x58 #X key
- Y = 0x59 #Y key
- Z = 0x5A #Z key
- LWIN = 0x5B #Left Windows key (Natural keyboard)
- RWIN = 0x5C #Right Windows key (Natural keyboard)
- APPS = 0x5D #Applications key (Natural keyboard)
- SLEEP = 0x5F #Computer Sleep key
- NUMPAD0 = 0x60 #Numeric keypad 0 key
- NUMPAD1 = 0x61 #Numeric keypad 1 key
- NUMPAD2 = 0x62 #Numeric keypad 2 key
- NUMPAD3 = 0x63 #Numeric keypad 3 key
- NUMPAD4 = 0x64 #Numeric keypad 4 key
- NUMPAD5 = 0x65 #Numeric keypad 5 key
- NUMPAD6 = 0x66 #Numeric keypad 6 key
- NUMPAD7 = 0x67 #Numeric keypad 7 key
- NUMPAD8 = 0x68 #Numeric keypad 8 key
- NUMPAD9 = 0x69 #Numeric keypad 9 key
- MULTIPLY = 0x6A #Multiply key
- ADD = 0x6B #Add key
- SEPARATOR = 0x6C #Separator key
- SUBTRACT = 0x6D #Subtract key
- DECIMAL = 0x6E #Decimal key
- DIVIDE = 0x6F #Divide key
- F1 = 0x70 #F1 key
- F2 = 0x71 #F2 key
- F3 = 0x72 #F3 key
- F4 = 0x73 #F4 key
- F5 = 0x74 #F5 key
- F6 = 0x75 #F6 key
- F7 = 0x76 #F7 key
- F8 = 0x77 #F8 key
- F9 = 0x78 #F9 key
- F10 = 0x79 #F10 key
- F11 = 0x7A #F11 key
- F12 = 0x7B #F12 key
- F13 = 0x7C #F13 key
- F14 = 0x7D #F14 key
- F15 = 0x7E #F15 key
- F16 = 0x7F #F16 key
- F17 = 0x80 #F17 key
- F18 = 0x81 #F18 key
- F19 = 0x82 #F19 key
- F20 = 0x83 #F20 key
- F21 = 0x84 #F21 key
- F22 = 0x85 #F22 key
- F23 = 0x86 #F23 key
- F24 = 0x87 #F24 key
- NUMLOCK = 0x90 #NUM LOCK key
- SCROLL = 0x91 #SCROLL LOCK key
- LSHIFT = 0xA0 #Left SHIFT key
- RSHIFT = 0xA1 #Right SHIFT key
- LCONTROL = 0xA2 #Left CONTROL key
- RCONTROL = 0xA3 #Right CONTROL key
- LMENU = 0xA4 #Left MENU key
- RMENU = 0xA5 #Right MENU key
- BROWSER_BACK = 0xA6 #Browser Back key
- BROWSER_FORWARD = 0xA7 #Browser Forward key
- BROWSER_REFRESH = 0xA8 #Browser Refresh key
- BROWSER_STOP = 0xA9 #Browser Stop key
- BROWSER_SEARCH = 0xAA #Browser Search key
- BROWSER_FAVORITES = 0xAB #Browser Favorites key
- BROWSER_HOME = 0xAC #Browser Start and Home key
- VOLUME_MUTE = 0xAD #Volume Mute key
- VOLUME_DOWN = 0xAE #Volume Down key
- VOLUME_UP = 0xAF #Volume Up key
- MEDIA_NEXT_TRACK = 0xB0 #Next Track key
- MEDIA_PREV_TRACK = 0xB1 #Previous Track key
- MEDIA_STOP = 0xB2 #Stop Media key
- MEDIA_PLAY_PAUSE = 0xB3 #Play/Pause Media key
- LAUNCH_MAIL = 0xB4 #Start Mail key
- LAUNCH_MEDIA_SELECT = 0xB5 #Select Media key
- LAUNCH_APP1 = 0xB6 #Start Application 1 key
- LAUNCH_APP2 = 0xB7 #Start Application 2 key
- OEM_1 = 0xBA #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ';:' key
- OEM_PLUS = 0xBB #For any country/region, the '+' key
- OEM_COMMA = 0xBC #For any country/region, the ',' key
- OEM_MINUS = 0xBD #For any country/region, the '-' key
- OEM_PERIOD = 0xBE #For any country/region, the '.' key
- OEM_2 = 0xBF #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '/?' key
- OEM_3 = 0xC0 #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '`~' key
- OEM_4 = 0xDB #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '[{' key
- OEM_5 = 0xDC #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '\|' key
- OEM_6 = 0xDD #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ']}' key
- OEM_7 = 0xDE #Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the 'single-quote/double-quote' key
- OEM_8 = 0xDF #Used for miscellaneous characters; it can vary by keyboard.
- OEM_102 = 0xE2 #Either the angle bracket key or the backslash key on the RT 102-key keyboard
- PROCESSKEY = 0xE5 #IME PROCESS key
- PACKET = 0xE7 #Used to pass Unicode characters as if they were keystrokes. The PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input method
- ATTN = 0xF6 #Attn key
- CRSEL = 0xF7 #CrSel key
- EXSEL = 0xF8 #ExSel key
- EREOF = 0xF9 #Erase EOF key
- PLAY = 0xFA #Play key
- ZOOM = 0xFB #Zoom key
- NONAME = 0xFC #Reserved
- PA1 = 0xFD #PA1 key
- OEM_CLEAR = 0xFE #Clear key
- end
Expand to see the code.
Check Keys
- #==============================================================================
- # Name: Check Keys
- # Description: Converts a pressed key in a char
- #------------------------------------------------------------------------------
- # Developed by: PedroHLC
- # Version: 1.4
- #==============================================================================
- module Input
- module_function
- # Checks all keyboards keys and returns it char if was it pressed
- def check_keys(can_letters=true, can_numbers=true, can_symbol=true)
- return " " if getKeyPressed(VK::SPACE)
- up = isUpperingCase
- if can_letters == true
- if up
- return "A" if getKeyPressed(VK::A)
- return "B" if getKeyPressed(VK::B)
- return "C" if getKeyPressed(VK::C)
- return "D" if getKeyPressed(VK::D)
- return "E" if getKeyPressed(VK::E)
- return "F" if getKeyPressed(VK::F)
- return "G" if getKeyPressed(VK::G)
- return "H" if getKeyPressed(VK::H)
- return "I" if getKeyPressed(VK::I)
- return "J" if getKeyPressed(VK::J)
- return "K" if getKeyPressed(VK::K)
- return "L" if getKeyPressed(VK::L)
- return "M" if getKeyPressed(VK::M)
- return "N" if getKeyPressed(VK::N)
- return "O" if getKeyPressed(VK::O)
- return "P" if getKeyPressed(VK::P)
- return "Q" if getKeyPressed(VK::Q)
- return "R" if getKeyPressed(VK::R)
- return "S" if getKeyPressed(VK::S)
- return "T" if getKeyPressed(VK::T)
- return "U" if getKeyPressed(VK::U)
- return "V" if getKeyPressed(VK::V)
- return "W" if getKeyPressed(VK::W)
- return "X" if getKeyPressed(VK::X)
- return "Y" if getKeyPressed(VK::Y)
- return "Z" if getKeyPressed(VK::Z)
- else
- return "a" if getKeyPressed(VK::A)
- return "b" if getKeyPressed(VK::B)
- return "c" if getKeyPressed(VK::C)
- return "d" if getKeyPressed(VK::D)
- return "e" if getKeyPressed(VK::E)
- return "f" if getKeyPressed(VK::F)
- return "g" if getKeyPressed(VK::G)
- return "h" if getKeyPressed(VK::H)
- return "i" if getKeyPressed(VK::I)
- return "j" if getKeyPressed(VK::J)
- return "k" if getKeyPressed(VK::K)
- return "l" if getKeyPressed(VK::L)
- return "m" if getKeyPressed(VK::M)
- return "n" if getKeyPressed(VK::N)
- return "o" if getKeyPressed(VK::O)
- return "p" if getKeyPressed(VK::P)
- return "q" if getKeyPressed(VK::Q)
- return "r" if getKeyPressed(VK::R)
- return "s" if getKeyPressed(VK::S)
- return "t" if getKeyPressed(VK::T)
- return "u" if getKeyPressed(VK::U)
- return "v" if getKeyPressed(VK::V)
- return "w" if getKeyPressed(VK::W)
- return "x" if getKeyPressed(VK::X)
- return "y" if getKeyPressed(VK::Y)
- return "z" if getKeyPressed(VK::Z)
- end
- end
- if can_numbers == true
- if !up
- return "0" if getKeyPressed(VK::KEY_0)
- return "1" if getKeyPressed(VK::KEY_1)
- return "2" if getKeyPressed(VK::KEY_2)
- return "3" if getKeyPressed(VK::KEY_3)
- return "4" if getKeyPressed(VK::KEY_4)
- return "5" if getKeyPressed(VK::KEY_5)
- return "6" if getKeyPressed(VK::KEY_6)
- return "7" if getKeyPressed(VK::KEY_7)
- return "8" if getKeyPressed(VK::KEY_8)
- return "9" if getKeyPressed(VK::KEY_9)
- end
- if getLockKeyState(VK::NUMLOCK)
- return "0" if getKeyPressed(VK::NUMPAD0)
- return "1" if getKeyPressed(VK::NUMPAD1)
- return "2" if getKeyPressed(VK::NUMPAD2)
- return "3" if getKeyPressed(VK::NUMPAD3)
- return "4" if getKeyPressed(VK::NUMPAD4)
- return "5" if getKeyPressed(VK::NUMPAD5)
- return "6" if getKeyPressed(VK::NUMPAD6)
- return "7" if getKeyPressed(VK::NUMPAD7)
- return "8" if getKeyPressed(VK::NUMPAD8)
- return "9" if getKeyPressed(VK::NUMPAD9)
- end
- end
- if can_symbol == true
- if !up
- return ";" if getKeyPressed(VK::OEM_1)
- return "'" if getKeyPressed(VK::OEM_7)
- else
- return ":" if getKeyPressed(VK::OEM_1)
- return "\"" if getKeyPressed(VK::OEM_7)
- end
- return "!" if getKeyPressed(VK::KEY_1)
- return "@" if getKeyPressed(VK::KEY_2)
- return "#" if getKeyPressed(VK::KEY_3)
- return "$" if getKeyPressed(VK::KEY_4)
- return "%" if getKeyPressed(VK::KEY_5)
- return "¨" if getKeyPressed(VK::KEY_6)
- return "&" if getKeyPressed(VK::KEY_7)
- return "*" if getKeyPressed(VK::KEY_8)
- return "(" if getKeyPressed(VK::KEY_9)
- return ")" if getKeyPressed(VK::KEY_0)
- return "[" if getKeyPressed(VK::OEM_4)
- return "]" if getKeyPressed(VK::OEM_6)
- return "\/" if getKeyPressed(VK::OEM_5)
- return "*" if getKeyPressed(VK::MULTIPLY)
- return "+" if getKeyPressed(VK::ADD)
- return "," if getKeyPressed(VK::SEPARATOR)
- return "-" if getKeyPressed(VK::SUBTRACT)
- return "." if getKeyPressed(VK::DECIMAL)
- return "/" if getKeyPressed(VK::DIVIDE)
- end
- return ""
- end
- end
Expand to see the code.
Window_Edit
- #===============================================================================
- # Name: Window_Edit
- # Description: A window to type text/informations
- #------------------------------------------------------------------------------
- # Developed by: PedroHLC
- # Version: 1.2
- #===============================================================================
- class Window_Edit < Window_Base
- attr_accessor :index
- def initialize(x, y, width, height, max, password=false)
- @text_width = (width - 32)
- @text_height = (height - 32)
- super(x, y, width, height)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.contents.font.size = 16
- self.back_opacity = 160
- @max = max
- @text = []
- @index = 0
- @blink_time = 0
- @password = password
- refresh
- end
- def text
- final_text = ""
- for i in 0..(@text.size-1)
- if @text[i] != nil
- final_text += @text[i].to_s
- end
- end
- return final_text
- end
- def text=(value)
- @text = value.split
- end
- def refresh
- if @blink_time <= -20
- @blink_time = 10
- else
- @blink_time -= 1
- end
- @cursor_char = "|"
- cursorx = 0
- if @password
- see_text = Array.new(@text.size, '*')
- else
- see_text = @text
- end
- if @index > 0
- for i in 0..(see_text.size-1)
- if i == (@index-1)
- cursorx += contents.text_size(see_text[i]).width
- break
- else
- cursorx += contents.text_size(see_text[i]).width
- end
- end
- end
- self.contents.clear
- self.contents.draw_text(1, 0, @text_width, @text_height, see_text.to_s)
- if @blink_time <= 0
- self.contents.draw_text(cursorx, 0, 4, @text_height, '|')
- end
- end
- def add(char)
- return if !char.is_a?(String)
- return if char.to_s == nil.to_s
- temp = []
- for i in 0..(@text.size - 1)
- if i >= @index
- temp[i+1] = @text[i] if @text[i].to_s != nil.to_s
- elsif i < @index
- temp[i] = @text[i] if @text[i].to_s != nil.to_s
- end
- end
- temp[(@index)] = (char.to_s)
- @text = temp
- @index += 1
- end
- def add_array(array)
- return if !array.is_a?(Array)
- if @index >= @text.size
- @text.push(array)
- @index = @text.size
- else
- temp1 = []
- temp2 = []
- for i in 0..(@text.size - 1)
- if i < @index
- temp1.push(@text[i]) if @text[i].to_s != nil.to_s
- elsif i >= @index
- temp2.push(@text[i]) if @text[i].to_s != nil.to_s
- end
- end
- for i in 0..(array.size - 1)
- temp1.push(array[i]) if array[i].to_s != nil.to_s
- end
- for i in 0..(temp2.size - 1)
- temp1.push(temp2[i]) if temp2[i].to_s != nil.to_s
- end
- @index += array.size
- @text = temp1
- end
- end
- def clear
- @text = []
- @index = 0
- end
- def onReturn
- @text.clear
- end
- def update
- if Input.getKeyPressed(VK::RETURN)
- onReturn
- end
- if Input.getKeyPressed(VK::BACK)
- if @text.size.to_i <= 0 or @index <= 0
- $game_system.se_play($data_system.buzzer_se)
- else
- @text.delete_at(@index-1)
- @index -= 1 if @index >= 1
- end
- end
- if Input.getKeyPressed(VK::DELETE)
- if @text.size.to_i <= 0 or @text[@index] == nil
- $game_system.se_play($data_system.buzzer_se)
- else
- @text.delete_at(@index)
- end
- end
- #if Input.getKeyState(VK::CONTROL) and Input.getKeyPressed(VK::V)
- #clipboard = Aleworks::Clipboard.read.to_s.strip.split(//)
- #if ([email hidden]_s.size) < @max
- #add_array(clipboard)
- #return
- #else
- #$game_system.se_play($data_system.buzzer_se)
- #end
- #end
- char = Input.check_keys(true,true,true)
- if @text.to_s.size < @max
- add(char) if char != nil
- else
- $game_system.se_play($data_system.buzzer_se)
- end
- if Input.getKeyPressed(VK::LEFT)
- if @index <= 0
- $game_system.se_play($data_system.buzzer_se)
- else
- $game_system.se_play($data_system.cursor_se)
- @index -= 1
- end
- end
- if Input.getKeyPressed(VK::RIGHT)
- if @index >= @text.size
- $game_system.se_play($data_system.buzzer_se)
- else
- $game_system.se_play($data_system.cursor_se)
- @index += 1
- end
- end
- #print @text if Input.getKeyPressed(VK::UP)
- if Input.getKeyPressed(VK::KEND)
- $game_system.se_play($data_system.cursor_se)
- @index = @text.size
- end
- if Input.getKeyPressed(VK::HOME)
- $game_system.se_play($data_system.cursor_se)
- @index = 0
- end
- if @index <= 0
- @index = 0
- elsif @index >= @text.size
- @index = @text.size
- end
- refresh
- end
- end
Expand to see the code.
DLL Source:
- //Developed by PedroHLC
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <Mmsystem.h>
- #include <windows.h>
- #define DLLEXTERN extern "C" __declspec (dllexport)
- #define Qfalse ((VALUE)0)
- #define Qtrue ((VALUE)2)
- #define Qnil 4
- //#define NIL_P(v) ((VALUE)(v) == Qnil)
- #define FIXNUM_FLAG 0x01
- #define INT2FIX(i) ((VALUE)(((long)(i))<<1 | FIXNUM_FLAG))
- typedef unsigned long VALUE;
- typedef struct{
- unsigned long flags;
- VALUE klass;
- } RBasic;
- typedef struct{
- RBasic basic;
- long len;
- union {
- long capa;
- VALUE shared;
- } aux;
- VALUE *ptr;
- } RArray;
- DLLEXTERN int getInput (long rbkeys_id,
- long rboldkeys_id,
- long rbstates_id,
- long rbjoystick_id,
- long rbmousepos_id,
- long windowid){
- VALUE *rbkeys_arr = ((RArray*)(rbkeys_id << 1))->ptr;
- VALUE *rboldkeys_arr = ((RArray*)(rboldkeys_id << 1))->ptr;
- VALUE *rbstates_arr = ((RArray*)(rbstates_id << 1))->ptr;
- VALUE *rbjoysticks_arr = ((RArray*)(rbjoystick_id << 1))->ptr;
- VALUE *rbmousepos_arr = ((RArray*)(rbmousepos_id << 1))->ptr;
- //Old Keys
- for (int keycode = 0; keycode < 256; keycode++){
- if (rbkeys_arr[keycode] == Qtrue)
- rboldkeys_arr[keycode] = Qtrue;
- else
- rboldkeys_arr[keycode] = Qfalse;
- }
- //Keys
- for (int keycode = 0; keycode < 256; keycode++){
- if (GetAsyncKeyState(keycode) >> 8)
- rbkeys_arr[keycode] = Qtrue;
- else
- rbkeys_arr[keycode] = Qfalse;
- }
- //States
- rbstates_arr[0] = (GetKeyState(0x14)? Qtrue : Qfalse);
- rbstates_arr[1] = (GetKeyState(0x90)? Qtrue : Qfalse);
- rbstates_arr[2] = (GetKeyState(0x91)? Qtrue : Qfalse);
- //Mouse
- POINT input_MousePos;
- GetCursorPos(&input_MousePos);
- HWND hWnd = (HWND)windowid;
- ScreenToClient(hWnd, &input_MousePos);
- rbmousepos_arr[0] = INT2FIX(input_MousePos.x);
- rbmousepos_arr[1] = INT2FIX(input_MousePos.y);
- //Joystick
- if (joyGetNumDevs() > 0){
- JOYINFOEX input_JoypadInfo;
- input_JoypadInfo.dwSize = 52;
- input_JoypadInfo.dwFlags = 255;
- if (joyGetPosEx(0, &input_JoypadInfo) != JOYERR_UNPLUGGED){
- rbjoysticks_arr[0] = INT2FIX(input_JoypadInfo.dwButtons);
- rbjoysticks_arr[1] = INT2FIX(input_JoypadInfo.dwXpos);
- rbjoysticks_arr[2] = INT2FIX(input_JoypadInfo.dwYpos);
- rbjoysticks_arr[3] = INT2FIX(input_JoypadInfo.dwPOV);
- }else{
- rbjoysticks_arr[0] = Qnil;
- rbjoysticks_arr[1] = Qnil;
- rbjoysticks_arr[2] = Qnil;
- rbjoysticks_arr[3] = Qnil;
- }
- }
- return 0;
- }
Expand to see the code.
Demo (in Portuguese):
Download using DROPBOX.COM
Compiled DLL included in Demo. Not tested yet on RMVX.
As you seen this is a simple and common script, that's why I'll only makes update when it's necessary; anyway thanks for the interesting on it. 😀