Ultimate control: keyboard, mouse,input,bitmap,clipboard, and game screen, attention major Scripters, Ever wanted this? |
|
|
|
|
Apr 6 2008, 01:59 AM
|

Level 3

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled

|
#later added# for those wanting a simple mouse and keyboard script please see the topic recently started by vgvgf The Aleworks input module. As blizzard's post below suggests, If you are interested in having a versatile script for the experts please read on.
As some of you might know, I've been working on a game that is a joint yugioh magic the gathering game and in the process I needed to establish a way to to use Input.repeat?(Input::(any key or mouse code you can imagine)) so that I could build menus and have them triggered by keyboard or mouse. Now thanks to a scripted input module by Aleworks, with a few tweaks by me, Now I can go ex) 'if Input.repeat?(Input::D)==true; print " 'D' is pressed";end ' and if I were to press the 'd' key, I would get that print message popping up on to my screen. To use this script, copy and paste the Aleworks script provided below into your game below all else and above main, then go through every script above it using search(called up by control f) and search for every instance of 'Input::' . Change the ones used for canceling to (Input::CANCEL), change the ones used for confirming to (Input::CONFIRM), change the ones for pg left to (Input::PGL) and page right to (Input::PGR), change the ones that scroll down to (Input::DOWN), up is (Input::UP), left is (Input::LEFT) etc. If you wanted to say only let the right arrow key be used for moving right, you would use (Input::D_RIGHT), up in this case would be (Input::D_UP) etc. D stands for direction. Now to use mouse left or mouse right buttons , for mouse left use (Input::MOUSE_PRIMARY) and for right use (Input::MOUSE_SECONDARY). The script can be modified fairy easily to accommodate more buttons on mouse, if you should have need or want for that. escape button is (input::ESC), enter is (Input::ENTER), you get the idea. the concept applies to all the keys. number keys are represented as (Input::NUMKEY1), NUMKEY2, NUMKEY3, etc. F1, F2... are (Input::F1) etc. Oh you can also do cursor position but that one I'm still learning how it works. credit and glory be to vgvgf for this ingenious script. It is over 2500 lines long, minus a few hundred for his commentary.give credit to him if you use this wonderfully useful script. And also to me for creating the programmer friendly (Input:: ) It will take about a minute to copy the entire script. And it really is easy to use after the initial conversion over to it is made. see below posts for a couple more examples. CODE #======================================================================== = ==== # ** Interpreter #============================================================================= class Interpreter #--------------------------------------------------------------------------- # * Input Button #--------------------------------------------------------------------------- #SDK.log_overwrite(:Interpreter, :input_button) def input_button n = 1 if Input.trigger?(Input::LOWER_LEFT) n = 3 if Input.trigger?(Input::LOWER_RIGHT) n = 7 if Input.trigger?(Input::UPPER_LEFT) n = 9 if Input.trigger?(Input::UPPER_RIGHT) n = 2 if Input.trigger?(Input::DOWN) n = 4 if Input.trigger?(Input::LEFT) n = 6 if Input.trigger?(Input::RIGHT) n = 8 if Input.trigger?(Input::UP) n = 11 if Input.trigger?(Input::A) n = 12 if Input.trigger?(Input::B) n = 13 if Input.trigger?(Input::C) n = 14 if Input.trigger?(Input::X) n = 15 if Input.trigger?(Input::Y) n = 16 if Input.trigger?(Input::Z) n = 17 if Input.trigger?(Input::L) n = 18 if Input.trigger?(Input::R)
if !n.nil? $game_variables[@button_input_variable_id] = n $game_map.need_refresh = true @button_input_variable_id = 0 end end #--------------------------------------------------------------------------- # * Conditional Branch #--------------------------------------------------------------------------- #SDK.log_overwrite(:Interpreter, :command_111) def command_111 result = false case @parameters[0] when 0 result = ($game_switches[@parameters[1]] == (@parameters[2] == 0)) when 1 value1 = $game_variables[@parameters[1]] if @parameters[2] == 0 value2 = @parameters[3] else value2 = $game_variables[@parameters[3]] end case @parameters[4] when 0 result = (value1 == value2) when 1 result = (value1 >= value2) when 2 result = (value1 <= value2) when 3 result = (value1 > value2) when 4 result = (value1 < value2) when 5 result = (value1 != value2) end when 2 if @event_id > 0 key = [$game_map.map_id, @event_id, @parameters[1]] if @parameters[2] == 0 result = ($game_self_switches[key] == true) else result = ($game_self_switches[key] != true) end end when 3 if $game_system.timer_working sec = $game_system.timer / Graphics.frame_rate if @parameters[2] == 0 result = (sec >= @parameters[1]) else result = (sec <= @parameters[1]) end end when 4 actor = $game_actors[@parameters[1]] if actor != nil case @parameters[2] when 0 result = ($game_party.actors.include?(actor)) when 1 result = (actor.name == @parameters[3]) when 2 result = (actor.skill_learn?(@parameters[3])) when 3 result = (actor.weapon_id == @parameters[3]) when 4 result = (actor.armor1_id == @parameters[3] or actor.armor2_id == @parameters[3] or actor.armor3_id == @parameters[3] or actor.armor4_id == @parameters[3]) when 5 result = (actor.state?(@parameters[3])) end end when 5 enemy = $game_troop.enemies[@parameters[1]] if enemy != nil case @parameters[2] when 0 result = (enemy.exist?) when 1 result = (enemy.state?(@parameters[3])) end end when 6 character = get_character(@parameters[1]) if character != nil result = (character.direction == @parameters[2]) end when 7 if @parameters[2] == 0 result = ($game_party.gold >= @parameters[1]) else result = ($game_party.gold <= @parameters[1]) end when 8 result = ($game_party.item_number(@parameters[1]) > 0) when 9 result = ($game_party.weapon_number(@parameters[1]) > 0) when 10 result = ($game_party.armor_number(@parameters[1]) > 0) when 11 n = Input::DOWN if @parameters[1] == 2 n = Input::LEFT if @parameters[1] == 4 n = Input::RIGHT if @parameters[1] == 6 n = Input::UP if @parameters[1] == 8 result = (Input.press?(n)) when 12 result = eval(@parameters[1]) end @branch[@list[@index].indent] = result if @branch[@list[@index].indent] == true @branch.delete(@list[@index].indent) return true end return command_skip end end
#============================================================================= # *** Aleworks Input Module Add On 1(AIM Add On 1) #============================================================================= # Created by Aleworks # Version: 1.00 # Last Update: 29/03/2007 (day/month/year) #============================================================================= #==== Description ==== # This add on, is for making AIM, to save/load the combos data when the game # is saved by the default save script. #============================================================================= #==== Requeriments ==== # * Aleworks Input Module # - Version: 2.00 #============================================================================= #==== Classes & Methods ==== # ** Class Scene_Save # * Alias Method: # - write_save_data; Alias Name: aleworks_aim_sceneload_writesavedata # ** Class Scene_Load # * Alias Method: # - read_save_data; Alias Name: aleworks_aim_scenesave_readsavedata #=============================================================================
#============================================================================== # ** Scene_Save #============================================================================== class Scene_Save < Scene_File #-------------------------------------------------------------------------- # * Write Data #-------------------------------------------------------------------------- alias_method(:aleworks_aim_sceneload_writesavedata, :write_save_data) def write_save_data(file) aleworks_aim_sceneload_writesavedata(file) Marshal.dump(Input.combos, file) end end
#============================================================================== # ** Scene_Load #============================================================================== class Scene_Load < Scene_File #-------------------------------------------------------------------------- # * Read Data #--------------------------------------------------------------------------
alias_method(:aleworks_aim_scenesave_readsavedata, :read_save_data) def read_save_data(file) aleworks_aim_scenesave_readsavedata(file) Input.combos = Marshal.load(file) end end
#============================================================================= # *** Aleworks Keys Module(AKM) #============================================================================= # Created by Aleworks # Version: 1.11 # Last Update: 11/09/2007 (day/month/year) #============================================================================= #==== Description ==== # This module, is a complement for AIM(Aleworks Input Module). It contains all # virtual keys named, from keyboard and mouse, for their use in AIM. #============================================================================= #==== Credits ==== # * Me(tm) # - Codes for: Keys.var_name? method, and Keys.var_vk? method #============================================================================= #==== Version History ==== # * 1.10 # - All the lacking virtual keys added(74 keys added) # - Keys.name? method improved # - New methods: Keys.var_name?; Keys.vk?; Keys.var_vk? # * 1.11 # - Fixed Bug between Enter and Clear virtual codes #============================================================================= #==== Instructions ==== # For reading a virtual key use: Keys::VIRTUALKEY, where VIRTUALKEY is the # name of the key you want to use. For example: Keys::A, will return 65, the # virtual key code of A key. #============================================================================= #==== Classes & Methods ==== # ** Module Keys # * Methods # - Keys.name?(vk) # vk is the virtual key that will have its name returned. # - Keys.var_name?(vk) # vk is the virtual key that will have its keys variable name returned. # - Keys.vk?(name) # name is the name of the key that will have its virtual key returned. # - Keys.var_vk?(name) # name is the name of the key variable that will have its virtual key # returned. #=============================================================================
#============================================================================= # ** Module Keys #============================================================================= module Keys #--------------------------------------------------------------------------- # * Mouse Buttons #--------------------------------------------------------------------------- MOUSE_LEFT = 1 # Mouse primary button (Normaly the left button) MOUSE_RIGHT = 2 # Mouse secondary button (Normaly the right button) MOUSE_MIDDLE = 4 # Mouse middle button MOUSE_4TH = 5 # Mouse fourth button MOUSE_5TH = 6 # Mouse fifth button #--------------------------------------------------------------------------- # * Miscellaneous Keys #--------------------------------------------------------------------------- BACKSPACE = 8 # Backspace key TAB = 9 # Tab key CLEAR = 12 # Clear key RETURN = 13 # Enter key SHIFT = 16 # Shift key CTRL = 17 # Control key ALT = 18 # Alt key PAUSE = 19 # Pause key ESCAPE = 27 # Escape key SPACE = 32 # Space bar key PGUP = 33 # Page Up key PGDN = 34 # Page Down key ENDS = 35 # End key HOME = 36 # Home key LEFT = 37 # Left Arrow key UP = 38 # Up Arrow key RIGHT = 39 # Right Arrow key DOWN = 40 # Down Arrow key SNAPSHOT = 44 # Print Screen key SELECT = 41 # Select key PRINT = 42 # Print key EXECUTE = 43 # Execute key INSERT = 45 # Insert key DELETE = 46 # Delete key HELP = 47 # Help key LEFT_SHIFT = 160 # Left Shift key RIGHT_SHIFT = 161 # Right Shift key LEFT_CONTROL = 162 # Left Control key RIGHT_CONTROL = 163 # Right Control key LEFT_ALT = 164 # Left Alt key RIGHT_ALT = 165 # Right Alt key #--------------------------------------------------------------------------- # * Number Keys #--------------------------------------------------------------------------- N0 = 48 # 0 key N1 = 49 # 1 key N2 = 50 # 2 key N3 = 51 # 3 key N4 = 52 # 4 key N5 = 53 # 5 key N6 = 54 # 6 key N7 = 55 # 7 key N8 = 56 # 8 key N9 = 57 # 9 key #--------------------------------------------------------------------------- # * Letters Keys #--------------------------------------------------------------------------- A = 65 # A key B = 66 # B key D = 68 # D key E = 69 # E key F = 70 # F key G = 71 # G key H = 72 # H key I = 73 # I key J = 74 # J key K = 75 # K key L = 76 # L key M = 77 # M key N = 78 # N key O = 79 # O key P = 80 # P key Q = 81 # Q key R = 82 # R key S = 83 # S key T = 84 # T key U = 85 # U key V = 86 # V key W = 87 # W key X = 88 # X key Y = 89 # Y key Z = 90 # Z key #--------------------------------------------------------------------------- # * Windows Keys #--------------------------------------------------------------------------- LWIN = 91 # Left Windows key (Microsoft Natural keyboard) RWIN = 92 # Right Windows key (Natural keyboard) APPS = 93 # Applications key (Natural keyboard) SLEEP = 95 # Computer Sleep key BROWSER_BAK = 166 # Browser Back key BROWSER_FORWARD = 167 # Browser Forward key BROWSER_REFRESH = 168 # Browser Refresh key BROWSER_STOP = 169 # Browser Stop key BROWSER_SEARCH = 170 # Browser Search key BROWSER_FAVORITES = 171 # Browser Favorites key BROWSER_HOME = 172 # Browser Start and Home key VOLUME_MUTE = 173 # Volume Mute key VOLUME_DOWN = 174 # Volume Down key VOLUME_UP = 175 # Volume Up key MEDIA_NEXT_TRACK = 176 # Next Track key MEDIA_PREV_TRACK = 177 # Previous Track key MEDIA_STOP = 178 # Stop Media key MEDIA_PLAY_PAUSE = 179 # Play/Pause Media key LAUNCH_MAIL = 180 # Start Mail key LAUNCH_MEDIA_SELECT = 181 # Select Media key LAUNCH_APP1 = 182 # Start Application 1 key LAUNCH_APP2 = 183 # Start Application 2 key PROCESS = 229 # Proccess key ATTN = 246 # Attn key CRSEL = 247 # CrSel key EXSEL = 248 # ExSel key EREOF = 249 # Erase EOF key PLAY = 250 # Play key ZOOM = 251 # Zoom key PA1 = 253 # PA1 key #--------------------------------------------------------------------------- # * Pad Keys #--------------------------------------------------------------------------- NUMPAD0 = 96 # 0 key NUMPAD1 = 97 # 1 key NUMPAD2 = 98 # 2 key NUMPAD3 = 99 # 3 key NUMPAD4 = 100 # 4 key NUMPAD5 = 101 # 5 key NUMPAD6 = 102 # 6 key NUMPAD7 = 103 # 7 key NUMPAD8 = 104 # 8 key NUMPAD9 = 105 # 9 key MULTIPLY = 106 # Multiply key (*) ADD = 107 # Add key (+) SEPARATOR = 108 # Separator key SUBTRACT = 109 # Subtract key (-) DECIMAL = 110 # Decimal key (.) DIVIDE = 111 # Divide key (/) #--------------------------------------------------------------------------- # * F Keys #--------------------------------------------------------------------------- F1 = 112 # F1 key F2 = 113 # F2 key F3 = 114 # F3 key F4 = 115 # F4 key F5 = 116 # F5 key F6 = 117 # F6 key F7 = 118 # F7 key F8 = 119 # F8 key F9 = 120 # F9 key F10 = 121 # F10 key F11 = 122 # F11 key F12 = 123 # F12 key F13 = 124 # F13 key F14 = 125 # F14 key F15 = 126 # F15 key F16 = 127 # F16 key F17 = 128 # F17 key F18 = 129 # F18 key F19 = 130 # F19 key F20 = 131 # F20 key F21 = 132 # F21 key F22 = 133 # F22 key F23 = 134 # F23 key F24 = 135 # F24 key #--------------------------------------------------------------------------- # * Mode Keys #--------------------------------------------------------------------------- CAPS_LOCK = 20 # Caps lock key NUM_LOCK = 144 # Num lock key SCROLL_LOCK = 145 # Scroll lock key KANA = 21 # Kana key JUNJA = 23 # Junja key FINAL = 24 # Final key KANJI = 25 # Kanji key CONVERT = 28 # Convert key NONCONVERT = 29 # Non convert key ACCEPT = 30 # Accept key MODECHANGE = 31 # Mode change request key #--------------------------------------------------------------------------- # * OEM Keys # - Keys used for miscellaneous characters; they can vary by keyboard. #--------------------------------------------------------------------------- OEM_1 = 186 # In USA 101/102 keyboards (; :) OEM_2 = 187 # In USA 101/102 keyboards (= +) OEM_3 = 188 # In USA 101/102 keyboards (, <) OEM_4 = 189 # In USA 101/102 keyboards (- _) OEM_5 = 190 # In USA 101/102 keyboards (. >) OEM_6 = 191 # In USA 101/102 keyboards (/ ?) OEM_7 = 192 # In USA 101/102 keyboards (` ~) OEM_8 = 219 # In USA 101/102 keyboards ([ {) OEM_9 = 220 # In USA 101/102 keyboards (\ |) OEM_10 = 221 # In USA 101/102 keyboards (] }) OEM_11 = 222 # In USA 101/102 keyboards (' ") OEM_13 = 223 # OEM key OEM_14 = 226 # OEM key OEM_15 = 146 # OEM key OEM_16 = 147 # OEM key OEM_17 = 148 # OEM key OEM_18 = 149 # OEM key OEM_19 = 150 # OEM key OEM_20 = 225 # OEM key OEM_21 = 227 # OEM key OEM_22 = 228 # OEM key OEM_23 = 230 # OEM key OEM_24 = 232 # OEM key OEM_25 = 240 # OEM key OEM_26 = 241 # OEM key OEM_27 = 242 # OEM key OEM_28 = 243 # OEM key OEM_29 = 244 # OEM key OEM_30 = 245 # OEM key OEM_CLEAR = 254 # OEM Clear key #--------------------------------------------------------------------------- # * Keys Names #--------------------------------------------------------------------------- KEYS_NAMES = {1=>'Mouse Primary',2=>'Mouse Secondary',3=>'Cancel', 4=>'Mouse Middle',5=>'Mouse 4th',6=>'Mouse 5th',8=>'Backspace',9=>'Tab', 12=>'Clear',13=>'Enter',16=>'Shift',17=>'Control',18=>'Alt',19=>'Pause', 20=>'Capitals Lock',21=>'Kana',23=>'Junja',24=>'Final',25=>'Kanji', 27=>'Escape',28=>'Convert',29=>'Non Convert',30=>'Accept',31=>'Mode Change', 32=>'Space',33=>'Page Up',34=>'Page Down',35=>'End',36=>'Home',37=>'Left', 38=>'Up',39=>'Right',40=>'Down',41=>'Select',42=>'Print',43=>'Execute', 44=>'Snapshot',45=>'Insert',46=>'Delete',47=>'Help',48=>'0',49=>'1',50=>'2', 51=>'3',52=>'4',53=>'5',54=>'6',55=>'7',56=>'8',57=>'9',65=>'A',66=>'B', 67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H',73=>'I',74=>'J',75=>'K', 76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q',82=>'R',83=>'S',84=>'T', 85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z',91=>'Left Windows', 92=>'Right Windows',93=>'Application',95=>'Sleep',96=>'PAD 0',97=>'PAD 1', 98=>'PAD 2',99=>'PAD 3',100=>'PAD 4',101=>'PAD 5',102=>'PAD 6',103=>'PAD 7', 104=>'PAD 8',105=>'PAD 9',106=>'*',107=>'+',108=>'Separator',109=>'-',110=>'.', 111=>'/',112=>'F1',113=>'F2',114=>'F3',115=>'F4',116=>'F5',117=>'F6',118=>'F7', 119=>'F8',120=>'F9',121=>'F10',122=>'F11',123=>'F12',124=>'F13',125=>'F14', 126=>'F15',127=>'F16',128=>'F17',129=>'F18',130=>'F19',131=>'F20',132=>'F21', 133=>'F22',134=>'F23',135=>'F24',144=>'Number Lock',145=>'Scroll Lock', 146=>'OEM 15',147=>'OEM 16',148=>'OEM 17',149=>'OEM 18',150=>'OEM 19', 160=>'Left Shift',161=>'Right Shift',162=>' Left Control',163=>'Right Control', 164=>' Left Alt',165=>'Right Alt',166=>'Browser Back',167=>'Browser Forward', 168=>'Browser Refresh',169=>'Browser Stop',170=>'Browser Search', 171=>'Browser Favorites',172=>'Browser Home',173=>'Volume Mute', 174=>'Volume Down',175=>'Volume Up',176=>'Media Next Track', 177=>'Media Previous Track',178=>'Media Stop',179=>'Media Play Pause', 180=>'Launch Mail',181=>'Launch Media Select',182=>'Launch Application', 183=>'Launch Application',186=>'OEM 1',187=>'OEM 2',188=>'OEM 3',189=>'OEM 4', 190=>'OEM 5',191=>'OEM 6',192=>'OEM 7',219=>'OEM 8',220=>'OEM 9',221=>'OEM 10', 222=>'OEM 11',223=>'OEM 13',225=>'OEM 20',226=>'OEM 14',227=>'OEM 21', 228=>'OEM 22',229=>'Proccess',230=>'OEM 23',232=>'OEM 24',240=>'OEM 25', 241=>'OEM 26',242=>'OEM 27',243=>'OEM 28',244=>'OEM 29',245=>'OEM 30', 246=>'ATTN',247=>'CRSEL',248=>'EXSEL',249=>'EREOF',250=>'Play',251=>'Zoom', 253=>'PA1',254=>'OEM Clear'} #--------------------------------------------------------------------------- # * Virtual Key to Key Name #--------------------------------------------------------------------------- def Keys.name?(vk) KEYS_NAMES[vk].nil? ? '???' : KEYS_NAMES[vk] end #--------------------------------------------------------------------------- # * Virtual Key to Virtual Key Variable Name #--------------------------------------------------------------------------- def Keys.var_name?(vk) Keys.constants.size.times do |index| if eval("Keys::#{Keys.constants[index]}") == vk return Keys.constants[index] end end '???' end #--------------------------------------------------------------------------- # * Key Name to Virtual Key #--------------------------------------------------------------------------- def Keys.vk?(name) KEYS_NAMES.invert[name].nil? ? 0 : KEYS_NAMES.invert[name] end #--------------------------------------------------------------------------- # * Virtual Key Variable Name to Virtual Key #--------------------------------------------------------------------------- def Keys.var_vk?(name) if Keys.constants.include?(name) eval("Keys::#{Keys.constants[Keys.constants.index(name)]}") else 0 end end end
#============================================================================= # *** Aleworks Library(ALibrary) #============================================================================= # Created by Aleworks # Version: 1.01 # Last Modification: 11/09/2007 (day/month/year) #============================================================================= #==== Description ==== # This script is a library, of tools and methods specialy designed for others # Aleworks scripts, however you are free to use it, as long as you give credit. #============================================================================= #==== Credits ==== # * Ruby 1.8 # - For the Win32::Registry class, that was the base for Aleworks::Registry # * Cybersam # - For some APIs functions for getting mouse position # * Nishikawa, Yasuhiro # - For some APIs for the Aleworks::Clipboard #============================================================================= #==== Version History ==== # * Version 1.01 # - Lots of fixes # - New methods: # - Aleworks: check_hang_up; translate_string; get_window_rect # - API: get_client_rect # - String: trans_undrawable_chr; insert # - Nil: clone # - Array: insert # - Bitmap: initialize; bmp_dump # - New constants: # - Aleworks: ASCII_TABLE; TRANSLATE_TABLE #============================================================================= #==== Classes & Methods ==== # ** Module Aleworks # * Constants: # - Active_Window # Id of the Game window. # - Current_Process_Id # Id of the Game process. # - Keyboard_Layout # Id of the used keyboard layout. # - ASCII_TABLE # Hash containing the characters corresponding to each of the 255 ascii # codification. # - TRANSLATE_TABLE # Hash containing the characters corresponding to the back references. # * Methods: # - Aleworks.get_keyboard_layout_name # Returns an array containing the name of the keyboard layout, and its # abbreviation. # - Aleworks.get_current_desktop_path # Returns the path of the user desktop folder. # - Aleworks.get_current_userdocuments_path # Returns the path of the user personal documents folder. # - Aleworks.get_common_desktop_path # Returns the path of the common desktop folder. # - Aleworks.get_common_usersdocuments_path # Returns the path of the common personal documents folder. # - Aleworks.get_fonts_folder_path # Returns the path of the common users personal documents folder. # - Aleworks.get_fonts_names # Returns all usable fonts names. # - Aleworks.get_mouse_swap_buttons_flag # Returns 1 if the mouse button are inverted, 0 instead. # - Aleworks.get_mouse_position # Returns an array with the coordinates of the mouse cursor. # - Aleworks.get_mouse_window_position([hwnd]) # Returns an array with the coordinates of the mouse cursor, in the given # hwnd. If hwnd is not given, it will be used the rgss player. # - Aleworks.check_hang_up(time) # Updates the module Graphics for prevention of a System Stack Error. # - Aleworks.translate_string(string) # Returns the translation of back reference characters to normal # characters. # - Aleworks.get_window_rect([hwnd]) # Returns an array containing the rect of the given window. If hwnd is not # given, it will be the game window. # Note: The rect includes the borders and title bar of the window. # ** Module Aleworks::API # * Methods: # - API.get_rtp_path([rtp]) # Returns the folder path of the RTP number 'rtp'-1. If 'rtp' is not used, # it will be number 0. # - API.get_keyboard_state # Returns a 256 byte string containing the virtual keys states. # - API.get_keyboard_layout_name # Returns a 9 byte string containing an id name of the keyboard layout. # - API.vk_to_ascii(vk) # Translates the given virtual key to an ASCII character. # - API.get_pps(tag, id, file) # Returns the value of the given id, of the given tag, of the given ini # file. # - API.get_window_placement([hwnd]) # Returns an array with the placement of the given window. If hwnd is not # given, it will be used the rgss player. # - API.get_cursor_pos # Returns an unpacked mouse coordinates. # - API.get_client_rect([hwnd]) # Returns an array containing the rect of the given window. If hwnd is not # given, it will be the game window. # ** Module Aleworks::Ini # * Methods: # - get_string(id[, tag[, file]]) # Returns the value of the given id, of the given tag, of the given ini # file. If the tag is not given, it will be used 'Game', and if the file # is not given, it will be used '.\\Game.ini'. # - set_string(string, id[, tag[, file]]) # Writes the value to the given id, of the given tag, of the given ini # file. If the tag is not given, it will be used 'Game', and if the file # is not given, it will be used '.\\Game.ini'. # ** Module Aleworks::Clipboard # * Methods: # - read # Returns the data contained in the Windows Clipboard. # - write(data) # Writes 'data' to the Windows Clipboard. # - empty # Clears the data of the Windows Clipboard. # ** Module Aleworks::Registry # * Constants: # - HKEYS # Used internaly, for translate the strings HKEYS to numeric. # * Methods: # - read_entry(key, entry) # Returns the value of the given entry, of the given key. # - enum_keys(key) # Returns an Array value containing all subkeys of the given key. # - enum_entries(key) # Returns an Array value containing all entries of the given key. # ** Class Array # * Methods: # - clone_all # Creates a copy of the object, and all it's sub values. # - to_hash # Creates a hash using the index of the values as the keys. # - rindexes(*values) # Returns the indices of all values contained in 'values'. # - deep([deep]) # Returns the max count of the continuated sub contained arrays/hashs. # 'deep' is the starting count + 1. If it is not given, will be used -1. # Examples: # - p [1, 2, 3].deep => 0 # - p [1, 2, [3]].deep => 1 # - p [[1], 2, [3]].deep => 1 # - p [[[1], 2, 3]].deep => 2 # - p [[[[[[1]]]]]].deep => 5 # - all_flatten; all_flatten! # Similar to flatten, but it will affect the Hash, too. Used with ! will # modify self. # ** Class Hash # * Methods: # - clone_all # Creates a copy of the object, and all it's sub values and keys. # - deep([deep]) # See Array.deep. # - fusion # Returns an Array, where will be combined using '+' each key and value. # If at least one key can't be combined with its value, will raise an # Errno::EINVAL error. # ** Class String # * Methods: # - pixel_width([size[, name]]) # Returns the width in pixel of the string. # - pixel_height([size[, name]]) # Returns the height in pixel of the string. # - width_slice(width[, size[, name]]) # Returns an Array containing Strings with theirs pixel_width, equal or # less than width. # - font_size_width(width[, name]]) # Returns the max font size, that will not cut the String when displayed # with the given width. Returns nil, if no size is available. # - font_size_height(height[, name]]) # Returns the max font size, that will not cut the String when displayed # with the given height. Returns nil, if no size is available. # - font_size(width, height[, name]]) # Returns the max font size, that will not cut the String when displayed # with the given width and height. Returns nil, if no size is available. # - trans_undrawable_chr([font[, chr]]) # Returns a string with all the undrawable characters for the given "font" # replaced with "chr". If "font" is not given will be used the default font # options. If "chr is not given, it will be "?". # ** Class Bitmap # * Alias method: # - draw_text; Alias Name: alibrary_aleworks_bitmap_drawtext # Allows to draw text using arrays, hashs, or other classes. # - initialize # If a block is given the Bitmap class will be returned and after the # block ends the Bitmap will be disposed. # - bmp_dump([filename[, background_color]) # Creates a ".bmp" file with the filename given from the Bitmap class. If # filename is not given it will automatically maked. If background_color is # given(as Color class) all the pixels from the Bitmap that have # transparencies will be mixed with the given color. # ** Module Graphics # * Constants # - Update # Used for calling automaticaly methods when Graphics module is updated. # For adding an auto-update, add an Array to the UPDATE array containg # as first value the class/module as a Constant and as second value the # method of the class/module to be updated as a symbol. # * Alias method: # - update; alibrary_aleworks_graphics_update # Allows to update multiple frames using Graphics.update(frames), where # frames are the count to be updated. # ** Class Nil # * Replaced method: # - clone # Removes the 'Nil can't be cloned error'. #=============================================================================
#============================================================================= # ** Module Aleworks #============================================================================= module Aleworks module_function #========================================================================== = # ** Module Aleworks::API #========================================================================== = module API module_function #------------------------------------------------------------------------- # APIs Definitions #------------------------------------------------------------------------- BlockInput = Win32API.new('user32', 'BlockInput', 'L', 'L') ClientToScreen = Win32API.new('user32', 'ClientToScreen', 'LP', 'L') CloseClipboard = Win32API.new('user32', 'CloseClipboard', '', 'L') EmptyClipboard = Win32API.new('user32', 'EmptyClipboard', '', 'L') GetActiveWindow = Win32API.new('user32', 'GetActiveWindow', '', 'L') GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'L', 'L') GetClientRect = Win32API.new('user32', 'GetClientRect', 'LP', 'L') GetClipboardData = Win32API.new('user32', 'GetClipboardData', 'L', 'L') GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'P', 'L') GetDoubleClickTime = Win32API.new('user32', 'GetDoubleClickTime', '', 'L') GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L') GetKeyboardLayoutName =Win32API.new('user32','GetKeyboardLayoutName','P','L') GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', 'P', 'L') GetKeyState = Win32API.new('user32', 'GetKeyState', 'L', 'L') GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'L', 'L') GetWindowPlacement = Win32API.new('user32', 'GetWindowPlacement', 'LP', 'L') Keybd_Event = Win32API.new('user32', 'keybd_event', 'LLLL', '') OpenClipboard = Win32API.new('user32', 'OpenClipboard', 'L', 'L') ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'LP', 'L') SetClipboardData = Win32API.new('user32', 'SetClipboardData', 'LL', 'L') ShowCursor = Win32API.new('user32', 'ShowCursor', 'L', 'L') ToAsciiEx = Win32API.new('user32', 'ToAsciiEx', 'LLPPLL', 'L') GetCurrentProcessId = Win32API.new('kernel32','GetCurrentProcessId', '','L') GPPSA = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L') WPPSA = Win32API.new('kernel32', 'WritePrivateProfileStringA', 'PPPP', 'L') GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'LL', 'L') GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L') GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'L', 'L') GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'L', '') RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') RegEnumKeyExA = Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPLLLP', 'L') RegEnumValueA = Win32API.new('advapi32', 'RegEnumValueA', 'LLPPPPPP', 'L') RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L') RegQueryValueExA = Win32API.new('advapi32', 'RegQueryValueExA','LPLPPP', 'L') begin Memcpy = Win32API.new('ntdll', 'memcpy', 'PPL', 'L') rescue Memcpy = Win32API.new('crtdll', 'memcpy', 'PPL', 'L') end ['3', '2', '1', '0'].each do |n| _break = false ['E', 'J'].each do |l| dll = 'RGSS10' + n + l begin RGSSGetRTPPath = Win32API.new(dll, 'RGSSGetRTPPath', 'L', 'L') RGSSGetPathWithRTP = Win32API.new(dll, 'RGSSGetPathWithRTP', 'L', 'P') _break = true rescue end break if _break end break if _break end #------------------------------------------------------------------------- # * Get RTP Path #------------------------------------------------------------------------- def get_rtp_path(rtp = 0) RGSSGetPathWithRTP.call(RGSSGetRTPPath.cal(rtp)) end #------------------------------------------------------------------------- # * Get Keyboard Input State #------------------------------------------------------------------------- def get_keyboard_state buffer = ' ' * 256 GetKeyboardState.call(buffer) buffer end #------------------------------------------------------------------------- # * Get Keyboard Layout Name #------------------------------------------------------------------------- def get_keyboard_layout_name buffer = ' ' * 9 GetKeyboardLayoutName.call(buffer) buffer.chop end #------------------------------------------------------------------------- # * Virtual Key to String #------------------------------------------------------------------------- def vk_to_ascii(vk, alt_gr = false) buffer = ' ' * 2 state = API.get_keyboard_state if alt_gr state[17, 1] = "\201" state[18, 1] = "\201" end result = API::ToAsciiEx.call(vk, 0, state, buffer, 0, API.get_keyboard_layout) case result when 1..2 buffer[0, 1] else '' end end #------------------------------------------------------------------------- # * Get Private Profile String #------------------------------------------------------------------------- def get_pps(tag, id, file) buffer = "\0" * 255 GPPSA.call(tag, id, '', buffer, 255, file) buffer.delete!("\0") end #------------------------------------------------------------------------- # * Get Window Placement #------------------------------------------------------------------------- def get_window_placement(hwnd = Aleworks::Active_Window) buffer = [48].pack('L') + ' ' * 44 GetWindowPlacement.call(hwnd, buffer) buffer.unpack('L11') end #------------------------------------------------------------------------- # * Get Cursor Pos #------------------------------------------------------------------------- def get_cursor_pos buffer = ' ' * 8 result = GetCursorPos.call(buffer) if result != 0 buffer else nil end end #------------------------------------------------------------------------- # * Get Keyboard Layout #------------------------------------------------------------------------- def get_keyboard_layout GetKeyboardLayout.call(0) end #------------------------------------------------------------------------- # * Get Client Rect #------------------------------------------------------------------------- def get_client_rect(hwnd = Aleworks::Active_Window) buffer = ' ' * 16 GetClientRect.call(hwnd, buffer) buffer.unpack('L4') end end #========================================================================== = # ** Module Aleworks::Ini #========================================================================== = module Ini module_function #------------------------------------------------------------------------- # * Get String from Ini File #------------------------------------------------------------------------- def get_string(id, tag = 'Game', file = '.\\Game.ini') get_pps(tag, id, file) end #------------------------------------------------------------------------- # * Write String to Ini File #------------------------------------------------------------------------- def set_string(string, id, tag = 'Game', file = '.\\Game.ini') API::WPPSA.call(tag, id, string, file) end end #========================================================================== = # ** Module Aleworks::Clipboard #========================================================================== = module Clipboard module_function #------------------------------------------------------------------------- # * Read Clipboard Data #------------------------------------------------------------------------- def read API::OpenClipboard.call(0) data = API::GetClipboardData.call(7) API::CloseClipboard.call return '' if data == 0 lp = API::GlobalLock.call(data) len = API::GlobalSize.call(data) data2 = ' ' * (len - 1) API::Memcpy.call(data2, lp, len) API::GlobalUnlock.call(data) data2 end #------------------------------------------------------------------------- # * Write Data to Clipboard #------------------------------------------------------------------------- def write(data) API::OpenClipboard.call(0) API::EmptyClipboard.call set_data = API::GlobalAlloc.call(66, data.length + 1) len = [data.size + 1, API::GlobalSize.call(set_data)].min lp = API::GlobalLock.call(set_data) API::Memcpy.call(lp, "#{data}", len) API::GlobalUnlock.call(set_data) API::SetClipboardData.call(7, set_data) API::CloseClipboard.call end #------------------------------------------------------------------------- # * Clear Clipboard Data #------------------------------------------------------------------------- def empty API::EmptyClipboard.call end end #========================================================================== = # ** Module Aleworks::Registry #========================================================================== = module Registry module_function HKEYS = {'HKEY_CLASSES_ROOT' => 0x80000000,'HKEY_CURRENT_USER' => 0x80000001, 'HKEY_LOCAL_MACHINE' => 0x80000002, 'HKEY_USERS' => 0x80000003, 'HKEY_CURRENT_CONFIG' => 0x80000005} #------------------------------------------------------------------------- # * Read an Entry #------------------------------------------------------------------------- def read_entry(key, entry) key.sub!(/(.*?)\\/, '') if HKEYS[$1] != nil hkey = HKEYS[$1] else return nil end opened, type, size = [0].pack('V'), [0].pack('V'), [0].pack('V') API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened) opened = (opened + [0].pack('V')).unpack('V')[0] API::RegQueryValueExA.call(opened, entry, 0, type, 0, size) data = ' ' * (size + [0].pack('V')).unpack('V')[0] API::RegQueryValueExA.call(opened, entry, 0, type, data, size) API::RegCloseKey.call(opened) data = data[0, (size + [0].pack('V')).unpack('V')[0]] type = (type += [0].pack('V')).unpack('V')[0] case type when 1 data.chop when 2 data.chop.gsub(/%([^%]+)%/) { ENV[$1] || $& } when 3 data when 4 (data += [0].pack('V')).unpack('V')[0] when 5 data.unpack('N')[0] when 7 data.split(/\0/) when 11 (data.unpack('VV')[1] << 32) | data[0] else nil end end #------------------------------------------------------------------------- # * Enum Keys #------------------------------------------------------------------------- def enum_keys(key) key.sub!(/(.*?)\\/, '') if HKEYS[$1] != nil hkey = HKEYS[$1] else return nil end index, keys, opened = 0, [], [0].pack('V') API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened) opened = (opened + [0].pack('V')).unpack('V')[0] loop do name = ' ' * 514 size = [514].pack('V') result = API::RegEnumKeyExA.call(opened, index, name, size, 0, 0, 0, 0) if result == 0 keys.push(name[0, (size += [0].pack('V')).unpack('V')[0]]) index += 1 else break end end API::RegCloseKey.call(opened) keys end #------------------------------------------------------------------------- # * Enum Entries #------------------------------------------------------------------------- def enum_entries(key) key.sub!(/(.*?)\\/, '') if HKEYS[$1] != nil hkey = HKEYS[$1] else return nil end index, entries, opened = 0, [], [0].pack('V') API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened) opened = (opened + [0].pack('V')).unpack('V')[0] loop do name = ' ' * 514 size = [514].pack('V') result = API::RegEnumValueA.call(opened, index, name, size, 0, 0, 0, 0) if result == 0 entries.push(name[0, (size += [0].pack('V')).unpack('V')[0]]) index += 1 else break end end API::RegCloseKey.call(opened) entries end end #--------------------------------------------------------------------------- # Variables Declaration #--------------------------------------------------------------------------- Active_Window = API::GetActiveWindow.call Current_Process_Id = API::GetCurrentProcessId.call ASCII_TABLE = {1=>'?',2=>'?',3=>'?',4=>'?',5=>'?',6=>'?',7=>'•',8=>'?',9=>'?', 10=>'?',11=>'?',12=>'?',13=>'?',14=>'?',15=>'¤',16=>'?',17=>'?',18=>'?', 19=>'?',20=>'¶',21=>'§',22=>'?',23=>'?',24=>'?',25=>'?',26=>'?',27=>'?', 28=>'?',29=>'?',30=>'?',31=>'?',32=>' ',33=>'!',34=>'"',35=>'#',36=>'$', 37=>'%',38=>'&',39=>"'",40=>'(',41=>')',42=>'*',43=>'+',44=>',',45=>'-', 46=>'.',47=>'/',48=>'0',49=>'1',50=>'2',51=>'3',52=>'4',53=>'5',54=>'6', 55=>'7',56=>'8',57=>'9',58=>':',59=>';',60=>'<',61=>'=',62=>'>',63=>'?', 64=>'@',65=>'A',66=>'B',67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H', 73=>'I',74=>'J',75=>'K',76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q', 82=>'R',83=>'S',84=>'T',85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z', 91=>'[',92=>'\\',93=>']',94=>'^',95=>'_',96=>'`',97=>'a',98=>'b',99=>'c', 100=>'d',101=>'e',102=>'f',103=>'g',104=>'h',105=>'i',106=>'j',107=>'k', 108=>'l',109=>'m',110=>'n',111=>'o',112=>'p',113=>'q',114=>'r',115=>'s', 116=>'t',117=>'u',118=>'v',119=>'w',120=>'x',121=>'y',122=>'z',123=>'{', 124=>'|',125=>'}',126=>'~',127=>'¦',128=>'Ç',129=>'ü',130=>'é',131=>'â', 132=>'ä',133=>'à',134=>'å',135=>'ç',136=>'ê',137=>'ë',138=>'è',139=>'ï', 140=>'î',141=>'́',142=>'Ä',143=>'Å',144=>'É',145=>'æ',146=>'Æ',147=>'ô', 148=>'ö',149=>'̣',150=>'û',151=>'ù',152=>'ÿ',153=>'Ö',154=>'Ü',155=>'ø', 156=>'£',157=>'Ø',158=>'×',159=>'ƒ',160=>'á',161=>'í',162=>'ó',163=>'ú', 164=>'ñ',165=>'Ñ',166=>'ª',167=>'º',168=>'¿',169=>'®',170=>'¬',171=>'½', 172=>'¼',173=>'¡',174=>'«',175=>'»',176=>'¦',177=>'¦',178=>'¦',179=>'¦', 180=>'¦',181=>'Á',182=>'Â',183=>'À',184=>'©',185=>'¦',186=>'¦',187=>'+', 188=>'+',189=>'¢',190=>'¥',191=>'+',192=>'+',193=>'-',194=>'-',195=>'+', 196=>'-',197=>'+',198=>'ă',199=>'Ă',200=>'+',201=>'+',202=>'-',203=>'-', 204=>'¦',205=>'-',206=>'+',207=>'¤',208=>'đ',209=>'Đ',210=>'Ê',211=>'Ë', 212=>'È',213=>'i',214=>'Í',215=>'Î',216=>'Ï',217=>'+',218=>'+',219=>'¦', 220=>'_',221=>'¦',222=>'̀',223=>'¯',224=>'Ó',225=>'ß',226=>'Ô',227=>'̉', 228=>'ơ',229=>'Ơ',230=>'µ',231=>'₫',232=>'̃',233=>'Ú',234=>'Û',235=>'Ù', 236=>'ư',237=>'Ư',238=>'¯',239=>'´',240=>'',241=>'±',242=>'=',243=>'¾', 244=>'¶',245=>'§',246=>'÷',247=>'¸',248=>'°',249=>'¨',250=>'•',251=>'¹', 252=>'³',253=>'²',254=>'¦',255=>' '} TRANSLATE_TABLE = {"\225"=>'•',"\244"=>'¤',"\266"=>'¶',"\247"=>'§',"\307"=>'Ç', "\374"=>'ü',"\351"=>'é',"\342"=>'â',"\344"=>'ä',"\340"=>'à',"\345"=>'å', "\347"=>'ç',"\352"=>'ê',"\353"=>'ë',"\350"=>'è',"\357"=>'ï',"\356"=>'î', "\354"=>'́',"\304"=>'Ä',"\305"=>'Å',"\311"=>'É',"\346"=>'æ',"\306"=>'Æ', "\364"=>'ô',"\366"=>'ö',"\362"=>'̣',"\373"=>'û',"\371"=>'ù',"\377"=>'ÿ', "\326"=>'Ö',"\334"=>'Ü',"\370"=>'ø',"\243"=>'£',"\330"=>'Ø',"\327"=>'×', "\203"=>'ƒ',"\341"=>'á',"\355"=>'í',"\363"=>'ó',"\372"=>'ú',"\361"=>'ñ', "\321"=>'Ñ',"\252"=>'ª',"\272"=>'º',"\277"=>'¿',"\256"=>'®',"\254"=>'¬', "\275"=>'½',"\274"=>'¼',"\241"=>'¡',"\253"=>'«',"\273"=>'»',"\301"=>'Á', "\302"=>'Â',"\300"=>'À',"\251"=>'©',"\242"=>'¢',"\245"=>'¥',"\343"=>'ă', "\303"=>'Ă',"\244"=>'¤',"\360"=>'đ',"\320"=>'Đ',"\312"=>'Ê',"\313"=>'Ë', "\310"=>'È',"\315"=>'Í',"\316"=>'Î',"\317"=>'Ï',"\314"=>'̀',"\257"=>'¯', "\323"=>'Ó',"\337"=>'ß',"\324"=>'Ô',"\322"=>'̉',"\365"=>'ơ',"\325"=>'Ơ', "\265"=>'µ',"\376"=>'₫',"\336"=>'̃',"\332"=>'Ú',"\333"=>'Û',"\331"=>'Ù', "\375"=>'ư',"\335"=>'Ư',"\257"=>'¯',"\264"=>'´',"\255"=>'',"\261"=>'±', "\276"=>'¾',"\266"=>'¶',"\247"=>'§',"\367"=>'÷',"\270"=>'¸',"\260"=>'°', "\250"=>'¨',"\267"=>'•',"\271"=>'¹',"\263"=>'³',"\262"=>'²',"\240"=>' ', "\t"=>' ',"\200"=>'€'} #--------------------------------------------------------------------------- # * Get Current User Deskot Path #--------------------------------------------------------------------------- def get_current_desktop_path key = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\' Registry.read_entry(key + 'Explorer\\Shell Folders', 'Desktop') end #--------------------------------------------------------------------------- # * Get Current User Personal Folder Path #--------------------------------------------------------------------------- def get_current_userdocuments_path key = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\' Registry.read_entry(key + 'Explorer\\Shell Folders', 'Personal') end #--------------------------------------------------------------------------- # * Get Common Deskot Path #--------------------------------------------------------------------------- def get_common_desktop_path key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\Windows\\CurrentVersion\\' Registry.read_entry(key + 'Explorer\\Shell Folders', 'Common Desktop') end #--------------------------------------------------------------------------- # * Get Common Users Personal Folder Path #--------------------------------------------------------------------------- def get_common_usersdocuments_path key = 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\' Registry.read_entry(key + 'Explorer\\Shell Folders', 'Common Documents') end #--------------------------------------------------------------------------- # * Get Fonts Folder Path #--------------------------------------------------------------------------- def get_fonts_folder_path key = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\' Registry.read_entry(key + 'Explorer\\Shell Folders', 'Fonts') end #--------------------------------------------------------------------------- # * Get Fonts Names #--------------------------------------------------------------------------- def get_fonts_names key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\#{ENV['OS'].sub(/_/,' ')}\\" fonts = Registry.enum_entries(key + 'CurrentVersion\\Fonts') fonts.each_index {|f| fonts[f].sub!(' (TrueType)', '') fonts[f] = nil if !Font.exist?(fonts[f]) }.delete(nil) fonts end #--------------------------------------------------------------------------- # * Get Mouse Swap Buttons Flag #--------------------------------------------------------------------------- def get_mouse_swap_buttons_flag key = 'HKEY_CURRENT_USER\\Control Panel\\Mouse' Registry.read_entry(key, 'SwapMouseButtons').to_i end #--------------------------------------------------------------------------- # * Get Mouse Position #--------------------------------------------------------------------------- def get_mouse_position pos = API.get_cursor_pos if pos.nil? nil else pos.unpack('L2') end end #--------------------------------------------------------------------------- # * Get Mouse Window Position #--------------------------------------------------------------------------- def get_mouse_window_position(hwnd = Active_Window) pos = API.get_cursor_pos if pos.nil? nil else result = API::ScreenToClient.call(hwnd, pos) if result != 0 pos = pos.unpack('L2') max_x, max_y = API.get_client_rect[2] - 1, API.get_client_rect[3] - 1 if pos[0] >= 0 and pos[1] >= 0 and pos[0] <= max_x and pos[1] <= max_y pos else nil end else nil end end end #--------------------------------------------------------------------------- # * Get Window Rect #--------------------------------------------------------------------------- def get_window_rect(hwnd = Active_Window) placement = API.get_window_placement(hwnd)[7..10] width = placement[2] - placement[0] height = placement[3] - placement[1] [placement[0], placement[1], width, height] end #--------------------------------------------------------------------------- # * Get Keyboard Layout Name #--------------------------------------------------------------------------- def get_keyboard_layout_name id = API.get_keyboard_layout_name key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout' name = Registry.read_entry(key + 's\\' + id, 'Layout Text') initials = Registry.read_entry(key + '\\DosKeybCodes', id) name = name.nil? ? '' : name initials = initials.nil? ? '' :initials [translate_string(name), translate_string(initials)] end #--------------------------------------------------------------------------- # * Get Keyboard Layout Name #--------------------------------------------------------------------------- def translate_string(string, arrayed = false) translation = [] string.each_chr do |c| if TRANSLATE_TABLE.has_key?© translation << TRANSLATE_TABLE[c] else translation << c end end if arrayed translation else translation.join end end #--------------------------------------------------------------------------- # * check_hang_up #--------------------------------------------------------------------------- def check_hang_up(time) if time.sec <= Time.now.sec - 6 or time.min != Time.now.min Graphics.update Time.now else time end end end
#============================================================================= # ** Class Array #============================================================================= class Array #--------------------------------------------------------------------------- # * Clone All #--------------------------------------------------------------------------- def clone_all cloned = self.clone cloned.each_index do |i| cloned[i] = cloned[i].clone_all rescue cloned[i].clone rescue cloned[i] end cloned end #--------------------------------------------------------------------------- # * To Hash #--------------------------------------------------------------------------- def to_hash hash = Hash.new self.each_index {|i| hash[i] = self[i]} hash end #--------------------------------------------------------------------------- # * Reverse Indexes #--------------------------------------------------------------------------- def rindexes(*values) array = Array.new self.each_index {|i| array.push(i) if values.include?(self[i])} array end #--------------------------------------------------------------------------- # * Deep #--------------------------------------------------------------------------- def deep(deep = -1) tmp_deep = deep + 1 deep = tmp_deep self.each do |i| deep = i.deep(tmp_deep) if deep < i.deep(tmp_deep) rescue nil end deep end #--------------------------------------------------------------------------- # * Flatten All #--------------------------------------------------------------------------- def all_flatten array = self.clone_all array.each_index do |i| if array[i].is_a?(Hash) array[i] = array[i].to_a end array[i] = array[i].all_flatten rescue array[i] end array.flatten! array end #--------------------------------------------------------------------------- # * Destructive Flatten All #--------------------------------------------------------------------------- def all_flatten! self.each_index do |i| if self[i].is_a?(Hash) self[i] = self[i].to_a end self[i] = self[i].all_flatten rescue self[i] end self.flatten! self end #--------------------------------------------------------------------------- # * Insert #--------------------------------------------------------------------------- def insert(*args) array = self.clone to_insert = args[1, args.size - 1] args[0] = [args[0], array.size - 1].min return array.reverse.concat(to_insert).reverse if args[0] < 0 array[0..args[0]].concat(to_insert).concat(array[args[0] + 1...array.size]) end end
#============================================================================= # ** Class Bitmap #============================================================================= class Bitmap #--------------------------------------------------------------------------- # * Initialize #--------------------------------------------------------------------------- if @alibrary_aleworks_bitmap_initialize.nil? alias_method(:alibrary_aleworks_bitmap_initialize, :initialize) @alibrary_aleworks_bitmap_initialize = true end def initialize(*args) alibrary_aleworks_bitmap_initialize(*args) if block_given? yield self self.dispose unless self.disposed? end end #--------------------------------------------------------------------------- # * Draw Text #--------------------------------------------------------------------------- unless self.method_defined?(:alibrary_aleworks_bitmap_drawtext) alias_method(:alibrary_aleworks_bitmap_drawtext, :draw_text) end def draw_text(*args) if args.size.between?(2,3) args[2] = 0 if args.size == 2 args[4] = args[1] args[5] = args[2] args[1] = args[0].y args[2] = args[0].width args[3] = args[0].height args[0] = args[0].x elsif args.size == 5 args[5] = 0 end if args[4].is_a?(Array) args[4].all_flatten! args[4].each do |t| t = t.nil? ? 'nil' : "#{t}" width = args[2].nil? ? self.text_size(t).width : args[2] height = args[3].nil? ? self.text_size('0').height : args[3] self.draw_text(args[0], args[1], width, height, t, args[5]) args[1] += height end return elsif args[4].is_a?(Hash) args[4] = args[4].fusion args[4].all_flatten! args[4].each do |t| t = t.nil? ? 'nil' : "#{t}" width = args[2].nil? ? self.text_size(t).width : args[2] height = args[3].nil? ? self.text_size('0').height : args[3] self.draw_text(args[0], args[1], width, height, t, args[5]) args[1] += height end return elsif !args[4].is_a?(String) if args[4].to_s == '' args[4] = args[4].inspect else args[4] = args[4].to_s end end args[2] = args[2].nil? ? self.text_size(args[4]).width + 2 : args[2] args[3] = args[3].nil? ? self.text_size('0').height + 2 : args[3] alibrary_aleworks_bitmap_drawtext(*args) end #--------------------------------------------------------------------------- # * Bitmap Save in Bmp Format #--------------------------------------------------------------------------- def bmp_dump(filename = nil, background_color = nil) bmp = self filename = "#{bmp.object_id}" if filename.nil? filename += '.bmp' if File.extname(filename) != '.bmp' if !background_color.nil? temp_bmp = bmp.clone rect = Rect.new(0, 0, temp_bmp.width, temp_bmp.height) bmp = Bitmap.new(temp_bmp.width, temp_bmp.height) bmp.fill_rect(rect, background_color) bmp.stretch_blt(rect, temp_bmp, rect) temp_bmp.dispose Graphics.update end file = File.open(filename, 'wb') file.write('BM') file.write([54 + (bmp.width * bmp.height * 24) / 8].pack('L')) file.write('ALEW') file.write([54].pack('L')) file.write([40].pack('L')) file.write([bmp.width].pack('L')) file.write([bmp.height].pack('L')) file.write([1].pack('L')[0, 2]) file.write([24].pack('L')[0, 2]) file.write([0, 0, 0, 0, 0, 0].pack('L6')) null_spaces = 0 if bmp.width / 4 != bmp.width / 4.0 if (bmp.width + 1) / 4 == (bmp.width + 1) / 4.0 null_spaces = 1 elsif (bmp.width + 2) / 4 == (bmp.width + 2) / 4.0 null_spaces = 2 elsif (bmp.width + 3) / 4 == (bmp.width + 3) / 4.0 null_spaces = 3 end end time = Time.now last_porcentage = -1 for y in (-bmp.height + 1)..0 line = '' for x in 0...bmp.width color = bmp.get_pixel(x, y.abs) line += [color.blue.to_i].pack('L')[0, 1] line += [color.green.to_i].pack('L')[0, 1] line += [color.red.to_i].pack('L')[0, 1] time = Aleworks.check_hang_up(time) if block_given? porcentage = (((y + bmp.height) * bmp.width + x)) * 100 porcentage /= bmp.height * bmp.width if porcentage > last_porcentage yield porcentage last_porcentage = porcentage end end end file.write(line) time = Aleworks.check_hang_up(time) end file.close end end
#============================================================================= # ** Class Hash #============================================================================= class Hash #--------------------------------------------------------------------------- # * Clone All #--------------------------------------------------------------------------- def clone_all cloned = self.clone cloned.each_key do |i| cloned[i] = cloned[i].clone_all rescue cloned[i].clone rescue cloned[i] end cloned end #--------------------------------------------------------------------------- # * Deep #--------------------------------------------------------------------------- def deep(deep = -1) tmp_deep = deep + 1 key_deep = tmp_deep value_deep = tmp_deep self.each do |k, v| key_deep = k.deep(tmp_deep) if key_deep < k.deep(tmp_deep) rescue nil value_deep = v.deep(tmp_deep) if value_deep < v.deep(tmp_deep) rescue nil end if key_deep > value_deep key_deep else value_deep end end #--------------------------------------------------------------------------- # * To Array, combining Key and Value #--------------------------------------------------------------------------- def fusion array = self.sort array.each_index do|i| begin array[i] = array[i][0] + array[i][1] rescue raise Errno::EINVAL, "Can't fusion Hash" end end end end
#============================================================================= # ** Nil Class #============================================================================= class NilClass def clone;end end
#============================================================================= # ** Class String #============================================================================= class String #--------------------------------------------------------------------------- # * Pixel Width of String #--------------------------------------------------------------------------- def pixel_width(*args) if args[0].is_a?(Font) size = args[0].size name = args[0].name bold = args[0].bold else size = args[0].nil? ? Font.default_size : args[0] name = args[1].nil? ? Font.default_name : args[1] bold = args[2].nil? ? Font.default_bold : args[2] end pix = 0 Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.size = size bitmap.font.bold = bold pix = bitmap.text_size(self).width end pix end #--------------------------------------------------------------------------- # * Pixel Height of String #--------------------------------------------------------------------------- def pixel_height(*args) if args[0].is_a?(Font) size = args[0].size name = args[0].name bold = args[0].bold else size = args[0].nil? ? Font.default_size : args[0] name = args[1].nil? ? Font.default_name : args[1] bold = args[2].nil? ? Font.default_bold : args[2] end pix = 0 Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.size = size bitmap.font.bold = bold pix = bitmap.text_size(self).height end pix end #--------------------------------------------------------------------------- # * Cut String to Strings with less or equal size than Width #--------------------------------------------------------------------------- def width_slice(width, *args) if args[0].is_a?(Font) size = args[0].size name = args[0].name bold = args[0].bold else size = args[0].nil? ? Font.default_size : args[0] name = args[1].nil? ? Font.default_name : args[1] bold = args[2].nil? ? Font.default_bold : args[2] end result = [''] txt = self.clone txt = txt.cscan Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.size = size bitmap.font.bold = bold txt.each_index do |i| if txt[i].is_a?(String) txt[i] = [txt[i], bitmap.text_size(txt[i]).width] if txt.include?(txt[i][0]) txt.collect! do |e| if e == txt[i][0] txt[i] else e end end end end end end act_width = 0 loop do if txt.size > 0 tmp_width = act_width + txt[0][1] tmp_width += txt[1][1] if txt.size > 1 if width >= act_width + txt[0][1] result[result.size - 1] += txt[0][0] act_width += txt[0][1] txt.delete_at(0) else result.push('') act_width = 0 end else break end end result end #--------------------------------------------------------------------------- # * Max Font Size for Width #--------------------------------------------------------------------------- def font_size_width(width, *args) if args[0].is_a?(Font) name = args[0].name bold = args[0].bold else name = args[0].nil? ? Font.default_name : args[0] bold = args[1].nil? ? Font.default_bold : args[1] end size = 6 Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.bold = bold for i in 6..96 bitmap.font.size = i size = i if bitmap.text_size(self).width <= width end end size end #--------------------------------------------------------------------------- # * Max Font Size for Height #--------------------------------------------------------------------------- def font_size_height(height, *args) if args[0].is_a?(Font) name = args[0].name bold = args[0].bold else name = args[0].nil? ? Font.default_name : args[0] bold = args[1].nil? ? Font.default_bold : args[1] end size = 6 Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.bold = bold for i in 6..96 bitmap.font.size = i size = i if bitmap.text_size(self).height <= height end end size end #--------------------------------------------------------------------------- # * Max Font Size for Width & Height #--------------------------------------------------------------------------- def font_size(width, height, *args) if args[0].is_a?(Font) name = args[0].name bold = args[0].bold else name = args[0].nil? ? Font.default_name : args[0] bold = args[1].nil? ? Font.default_bold : args[1] end size = 6 Bitmap.new(1, 1) do |bitmap| bitmap.font.name = name bitmap.font.bold = bold for i in 6..96 bitmap.font.size = i if bitmap.text_size(self).width <= width and bitmap.text_size(self).height <= height size = i end end end size end #--------------------------------------------------------------------------- # * Insert #--------------------------------------------------------------------------- def insert(*args) string = self to_insert = args[1, args.size - 1].join args[0] = [args[0], string.size - 1].min string[0..args[0]] + to_insert + string[args[0] + 1...string.size] end #--------------------------------------------------------------------------- # * Iterate each Character #--------------------------------------------------------------------------- def each_chr self.cscan.each {|chr| yield chr} end #--------------------------------------------------------------------------- # * Character Scan #--------------------------------------------------------------------------- def cscan chrs = [] for i in 0...self.size chrs.push(self[i..i]) end chrs end #--------------------------------------------------------------------------- # * One Character Scan #--------------------------------------------------------------------------- def oscan self.scan(/./) end #--------------------------------------------------------------------------- # * To ASCII Integer #--------------------------------------------------------------------------- def to_ascii_i self.unpack('B8')[0].to_i(2) end #--------------------------------------------------------------------------- # * Transform the undrawable Characters #--------------------------------------------------------------------------- def trans_undrawable_chr(font = Font.new, chr = '?') bmp = Bitmap.new(1, 1) bmp.font= font txt = '' oscan.each {|c| txt += (bmp.text_size©.width == 0) ? chr : c} txt end end
#============================================================================= # ** Module Graphics #============================================================================= module Graphics Update = [] class << self #------------------------------------------------------------------------- # * Multiple Graphics update & objects update #------------------------------------------------------------------------- unless self.method_defined?(:alibrary_aleworks_graphics_update) alias_method(:alibrary_aleworks_graphics_update, :update) end def update(frames = 0) alibrary_aleworks_graphics_update Update.each {|k| k[0].method(k[1]).call} update(frames - 1) if frames > 0 end end end
#============================================================================= # ** Module Input #============================================================================= module Input #--------------------------------------------------------------------------- # * Expand Input module with Aleworks Library #--------------------------------------------------------------------------- include Aleworks #--------------------------------------------------------------------------- # * Options #--------------------------------------------------------------------------- START_REPEAT_TIME = 10 REPEAT_TIME = 2 REITERATE_TIME = 20 MOUSE_INPUT = true MOUSE_DOUBLE_CLICK_TIME = nil MOUSE_DOUBLE_CLICK_PIX = 4 MOUSE_DRAG_PIX = 4 #--------------------------------------------------------------------------- # * Internal variables definition #--------------------------------------------------------------------------- @trigger, @trigger2, @repeat, @repeat2, @repeat3, @reiterate, @reiterate2, @reiterate3, @release, @release2 = ([[]] * 10).clone_all 256.times do |i| @trigger.push(false) @trigger2.push(false) @repeat.push(false) @repeat2.push(0) @reiterate.push(false) @reiterate2.push(0) @reiterate3.push(API::GetKeyState.call(i) & 1) @release.push(false) @release2.push(false) end @combos = {} @mouse_pos = nil @mouse_swap_buttons = Aleworks.get_mouse_swap_buttons_flag @mouse_primary_dc = [0, 0, [nil, nil]] @mouse_rectdrag = nil @mouse_draw = [] if MOUSE_DOUBLE_CLICK_TIME.nil? MOUSE_DOUBLE_CLICK_TIME = Graphics.frame_rate MOUSE_DOUBLE_CLICK_TIME *= (API::GetDoubleClickTime.call / 10) MOUSE_DOUBLE_CLICK_TIME /= 100 end #--------------------------------------------------------------------------- # * convert_keys (internal method) #--------------------------------------------------------------------------- # It reads the windows registry and returns the corresponding keys to the # F1 keys menu. #--------------------------------------------------------------------------- REG_KVALUES = {0=>32,1=>13,2=>27,3=>96,4=>16,5=>90,6=>88,7=>67,8=>86,9=>66, 10=>65,11=>83,12=>68,13=>81,14=>87} def convert_keys(key) keys = [] reg_key = 'HKEY_CURRENT_USER\\Software\\Enterbrain\\RGSS' data = Registry.read_entry(reg_key, 'ButtonAssign')[10, 25].scan(/./) 15.times {|i| keys.push(REG_KVALUES[i]) if key == data[i].unpack('C')[0]} keys end module_function :convert_keys #--------------------------------------------------------------------------- # * Keys Constants definitions #--------------------------------------------------------------------------- LMB, RMB, MMB, BACKSPACE, TAB, ENTER, SHIFT, CTRL, ALT, ESC, D_DOWN, D_LEFT, D_RIGHT, D_UP, SCACE = 1, 2, 4, 8, 9, 13, 16, 17, 18, 27, 40, 37,39, 38, 32 A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z=65,66,68,69,70, 71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90 F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12=112,113,114,115,116,117,118,119, 120,121,122,123 NUMKEY0,NUMKEY1,NUMKEY2,NUMKEY3,NUMKEY4,NUMKEY5,NUMKEY6,NUMKEY7,NUMKEY8, NUMKEY9 = 48,49,50,51,52,53,54,55,56,57 C=67 SPACE=32 LOWER_LEFT = 97 LOWER_RIGHT = 99 UPPER_LEFT = 103 UPPER_RIGHT = 105 DOWN = [98,83 ,40] LEFT = [100, 65,37] RIGHT = [102, 68,39] UP = [104, 87,38] #A = convert_keys(11) CANCEL = [8,27] CONFIRM = [13,32] #X = convert_keys(14) #Y = convert_keys(15) #Z = convert_keys(16) PGL = convert_keys(17).concat([33]) PGR = convert_keys(18).concat([34]) MOUSE_PRIMARY = 1 + @mouse_swap_buttons MOUSE_SECONDARY = 2 - @mouse_swap_buttons #========================================================================== = # ** Class Key_Combo #========================================================================== = class Key_Combo attr_accessor(:params, :restart_count, :restart_type, :update) #------------------------------------------------------------------------- # * Initialize #------------------------------------------------------------------------- def initialize(params, restart_count, restart_type, update) params.each_index do |i| if params[i].is_a?(Array) params[i][2] = [0, 0] if params[i].size == 2 params[i][3] = 0 if params[i].size == 3 params[i][1] = params[i][1].to_a if params[i][2].is_a?(Numeric) params[i][2] = [params[i][2], 0] elsif params[i][2].is_a?(Range) if params[i][2].exclude_end? params[i][2] = [params[i][2].first, params[i][2].last - 1] else params[i][2] = [params[i][2].first, params[i][2].last] end elsif params[i][2].is_a?(String) if !params[i][2][/(.*)\.\.\.(.*)/].nil? params[i][2] = [$1, ($2.to_i - 1).to_s] elsif !params[i][2][/(.*)\.\.(.*)/].nil? params[i][2] = [$1, $2] else params[i][2] = [params[i][2], 0] end elsif params[i][2].is_a?(Array) if params[i][2][0].is_a?(String) params[i][2][1] = params[i][2][1].to_s end if params[i][2][1].is_a?(String) params[i][2][0] = params[i][2][0].to_s end end end end if @update.is_a?(Array) @update.each_index do |i| @update[i] = @update[i].type.to_s end elsif @update.is_a?(Hash) @update = !@update @update.each do |k, v| @update[k] = @update[k].type.to_s end @update = !@update end @params = params @state = @params.clone_all @restart_count = restart_count @_restart_count = restart_count @restart_type = restart_type @update = update @last_state = @state.clone_all if @restart_type == 1 @frame_start = Graphics.frame_count @frame_end = nil @_true = nil @_end = false @start_check = false @end_check = false @restarts = 0 @frozen = false end #------------------------------------------------------------------------- # * Update #------------------------------------------------------------------------- def update return if @frozen or @_end or @params.size == 0 if @update.is_a?(Array) return if !@update.include?($scene.type.to_s) elsif @update.is_a?(Hash) if @update.has_key?($scene.type.to_s) return if eval(@update[$scene.type.to_s].to_s) end end if @state[0].is_a?(Numeric) @state[0] -= 1 check_true if @state[0] <= 0 elsif @state[0].is_a?(Array) if Input.press?(@state[0][1]) input_checked = true if @state[0][2][0].is_a?(Numeric) @start_check = true @state[0][2][0] -= 1 unless @state[0][2][0] <= 0 @state[0][2][1] -= 1 unless @state[0][2][1] <= 0 if @state[0][2][0] <= 0 and @state[0][2][1] <= 0 check_true return end elsif @state[0][2][0].is_a?(String) unless @state[0][2][0].to_i <= 0 @state[0][2][0] = (@state[0][2][0].to_i - 1).to_s end unless @state[0][2][1].to_i <= 0 @state[0][2][1] = (@state[0][2][1].to_i - 1).to_s end if @state[0][2][0].to_i <= 0 and @state[0][2][1].to_i <= 0 check_true return end end if @state[0][0].is_a?(String) if @state[0][0].to_i >= 0 @state[0][0] = (@state[0][0].to_i - 1).to_s is_false if @state[0][0].to_i == 0 end end else if @state[0][2][0].to_i <= 0 check_true return elsif @start_check is_false return end if @state[0][0].is_a?(String) if @state[0][0].to_i >= 0 @state[0][0] = (@state[0][0].to_i - 1).to_s is_false if @state[0][0].to_i == 0 end elsif @state[0][0].is_a?(Numeric) if @state[0][0] >= 0 @state[0][0] -= 1 unless @state[0][0] <= 0 is_false if @state[0][0] == 0 end end end end end #------------------------------------------------------------------------- def true? @_true end #------------------------------------------------------------------------- def end? @_end end #------------------------------------------------------------------------- def frozen? @frozen end #------------------------------------------------------------------------- def restarts_count? @restarts end #------------------------------------------------------------------------- def start_frame? @frame_start end #------------------------------------------------------------------------- def end_frame? @frame_end end #------------------------------------------------------------------------- def freeze @frozen = true end #------------------------------------------------------------------------- def unfreeze @frozen = false end #------------------------------------------------------------------------- def restart @state = @params.clone_all @last_state = @state.clone_all if @restart_type == 1 @restart_count = @_restart @frame_start = Graphics.frame_count @frame_end = nil @_true = nil @_end = false @start_check = false @restarts = 0 end #------------------------------------------------------------------------- def is_false if @restart_count <= -1 if @restart_type == 1 @state = @last_state.clone_all else @state = @params.clone_all end @restarts += 1 elsif @restart_count == 0 @_end = true @frame_end = Graphics.frame_count else if @restart_type == 1 @state = @last_state.clone_all else @state = @params.clone_all end @restart_count -= 1 @restarts += 1 end @start_check = false end #------------------------------------------------------------------------- def check_true if @state[0][3] > 0 @state[0][3] -= 1 elsif @state[0][3] == 0 @state.slice!(0) @last_state = @state.clone_all if @restart_type == 1 if @state.size == 0 @_true = true @_end = true @frame_end = Graphics.frame_count end end end private :is_false, :check_true end #--------------------------------------------------------------------------- # * Keys input state update #--------------------------------------------------------------------------- def Input.update state = API.get_keyboard_state.oscan state.each_index do |i| @repeat2[i] -= 1 if @repeat2[i] > 1 if state[i] == "\200" or state[i] == "\201" if @trigger2[i] @trigger[i] = false else @trigger[i] = true @trigger2[i] = true end if @repeat2[i] <= 1 @repeat2[i] = @repeat2[i] == 1 ? REPEAT_TIME : START_REPEAT_TIME @repeat2[i] += 1 @repeat[i] = true else @repeat[i] = false end @release2[i] = true else @trigger[i] = false @trigger2[i] = false @repeat[i] = false @repeat2[i] = 0 @release[i] = @release2[i] ? true : false @release2[i] = false end @reiterate2[i] -= 1 if @reiterate2[i] > 0 @reiterate[i] = false if @reiterate2[i] == 0 if (state[i] == "\001" or state[i] == "\201") and @reiterate3[i] == 0 @reiterate[i] = true @reiterate2[i] = REITERATE_TIME @reiterate3[i] = 1 elsif (state[i] == "\000" or state[i] == "\200") and @reiterate3[i] == 1 @reiterate[i] = true @reiterate2[i] = REITERATE_TIME @reiterate3[i] = 0 end end @combos.each_value {|c| c.update} if MOUSE_INPUT @mouse_pos = Aleworks.get_mouse_window_position case @mouse_primary_dc[0] when 0 if Input.trigger?(MOUSE_PRIMARY) and @mouse_pos != nil @mouse_primary_dc = [1, MOUSE_DOUBLE_CLICK_TIME, @mouse_pos.clone] end when 1 if @mouse_pos != nil if @mouse_primary_dc[1] > 0 and @mouse_pos[0].between?(@mouse_primary_dc[2][0] - MOUSE_DOUBLE_CLICK_PIX, @mouse_primary_dc[2][0] + MOUSE_DOUBLE_CLICK_PIX) and @mouse_pos[1].between?(@mouse_primary_dc[2][1] - MOUSE_DOUBLE_CLICK_PIX, @mouse_primary_dc[2][1] + MOUSE_DOUBLE_CLICK_PIX) @mouse_primary_dc[1] -= 1 @mouse_primary_dc[0, 1] = 2, 0 if Input.trigger?(MOUSE_PRIMARY) else @mouse_primary_dc = [0, 0, [nil, nil]] end else @mouse_primary_dc = [0, 0, [nil, nil]] end when 2 @mouse_primary_dc = [0, 0, [nil, nil]] end if Input.press?(MOUSE_PRIMARY) if @mouse_pos != nil if @mouse_rectdrag == nil @mouse_rectdrag = @mouse_pos.clone if Input.trigger?(MOUSE_PRIMARY) elsif @mouse_rectdrag.size == 2 if !@mouse_pos[0].between?(@mouse_rectdrag[0] - MOUSE_DRAG_PIX, @mouse_rectdrag[0] + MOUSE_DRAG_PIX) or !@mouse_pos[1].between?(@mouse_rectdrag[1] - MOUSE_DRAG_PIX, @mouse_rectdrag[1] + MOUSE_DRAG_PIX) @mouse_rectdrag.push(*@mouse_pos) end else @mouse_rectdrag[2, 3] = *@mouse_pos end else @mouse_rectdrag = nil end else @mouse_rectdrag = nil end @mouse_draw = [] end end #--------------------------------------------------------------------------- # * Press? #--------------------------------------------------------------------------- def Input.press?(vk) if vk.is_a?(Array) vk.each do |i| if i.is_a?(Array) returntrue = true i.each do |e| if e.is_a?(Array) returntrue2 = false e.each do |o| if !API::GetAsyncKeyState.call(o).between?(0, 1) returntrue2 = true end end returntrue = false if !returntrue2 elsif !API::GetAsyncKeyState.call(e).between?(0, 1) returntrue = false end end return true if returntrue else return true if !API::GetAsyncKeyState.call(i).between?(0, 1) end end false else !API::GetAsyncKeyState.call(vk).between?(0, 1) end end #--------------------------------------------------------------------------- # * Press? all #--------------------------------------------------------------------------- def Input.press_all(state = true) pressed = API.get_keyboard_state pressed = pressed.scan(/./) if state pressed.rindexes("\200", "\201") else pressed.rindexes("\000", "\001") end end #--------------------------------------------------------------------------- # * Trigger? #--------------------------------------------------------------------------- def Input.trigger?(vk) if vk.is_a?(Array) vk.each do |i| if i.is_a?(Array) returntrue = true i.each do |e| if e.is_a?(Array) returntrue2 = false e.each do |o| returntrue2 = true if @trigger[o] end returntrue = false if !returntrue2 elsif @trigger[e] returntrue = false end end return true if returntrue else return true if @trigger[i] end end false else @trigger[vk] end end #--------------------------------------------------------------------------- # * Trigger? all #--------------------------------------------------------------------------- def Input.trigger_all(state = true) @trigger.rindexes(state) end #--------------------------------------------------------------------------- # * Repeat? #--------------------------------------------------------------------------- def Input.repeat?(vk) if vk.is_a?(Array) vk.each do |i| if i.is_a?(Array) returntrue = true i.each do |e| if e.is_a?(Array) returntrue2 = false e.each do |o| returntrue2 = true if @repeat[o] end returntrue = false if !returntrue2 elsif @repeat[e] returntrue = false end end return true if returntrue else return true if @repeat[i] end end false else @repeat[vk] end end #--------------------------------------------------------------------------- # * Repeat? all #--------------------------------------------------------------------------- def Input.repeat_all(state = true) @repeat.rindexes(state) end #--------------------------------------------------------------------------- # * Reiterate? #--------------------------------------------------------------------------- def Input.reiterate?(num) if vk.is_a?(Array) vk.each do |i| if i.is_a?(Array) returntrue = true i.each do |e| if e.is_a?(Array) returntrue2 = false e.each do |o| returntrue2 = true if @reiterate[o] end returntrue = false if !returntrue2 elsif @reiterate[e] returntrue = false end end return true if returntrue else return true if @reiterate[i] end end false else @reiterate[vk] end end #--------------------------------------------------------------------------- # * Reiterate? all #--------------------------------------------------------------------------- def Input.reiterate_all(state = true) @reiterate.rindexes(state) end #--------------------------------------------------------------------------- # * Release? #--------------------------------------------------------------------------- def Input.release?(vk) if vk.is_a?(Array) vk.each do |i| if i.is_a?(Array) returntrue = true i.each do |e| if e.is_a?(Array) returntrue2 = false e.each do |o| returntrue2 = true if @release[o] end returntrue = false if !returntrue2 elsif @release[e] returntrue = false end end return true if returntrue else return true if @release[i] end end false else @release[vk] end end #--------------------------------------------------------------------------- # * Release? all #--------------------------------------------------------------------------- def Input.release_all(state = true) @release.rindexes(state) end #--------------------------------------------------------------------------- # * 4 Directions #--------------------------------------------------------------------------- def Input.dir4 return 2 if Input.press?(Input::DOWN) return 4 if Input.press?(Input::LEFT) return 6 if Input.press?(Input::RIGHT) return 8 if Input.press?(Input::UP) 0 end #--------------------------------------------------------------------------- # * 8 Directions #--------------------------------------------------------------------------- def Input.dir8 return 1 if Input.press?([[Input::DOWN, Input::LEFT]]) return 3 if Input.press?([[Input::DOWN, Input::RIGHT]]) return 7 if Input.press?([[Input::UP, Input::LEFT]]) return 9 if Input.press?([[Input::UP, Input::RIGHT]]) return 1 if Input.press?(Input::LOWER_LEFT) return 3 if Input.press?(Input::LOWER_RIGHT) return 7 if Input.press?(Input::UPPER_LEFT) return 9 if Input.press?(Input::UPPER_RIGHT) return 2 if Input.press?(Input::DOWN) return 4 if Input.press?(Input::LEFT) return 6 if Input.press?(Input::RIGHT) return 8 if Input.press?(Input::UP) 0 end #--------------------------------------------------------------------------- # * Activated? #--------------------------------------------------------------------------- def Input.activated?(vk) API::GetKeyState.call(vk) & 1 == 1 end #--------------------------------------------------------------------------- # * Key Click #--------------------------------------------------------------------------- def Input.key_click(vk) vk = vk.to_a vk.each {|k| API::Keybd_Event.call(k, 0, 0, 0)} vk.each {|k| API::Keybd_Event.call(k, 0, 2, 0)} end #--------------------------------------------------------------------------- # * Key Release #--------------------------------------------------------------------------- def Input.key_release(vk) vk = vk.to_a vk.each {|k| API::Keybd_Event.call(k, 0, 2, 0)} end #--------------------------------------------------------------------------- # * Key Press #--------------------------------------------------------------------------- def Input.key_press(vk) vk = vk.to_a vk.each {|k| API::Keybd_Event.call(k, 0, 0, 0)} end #--------------------------------------------------------------------------- # * Mouse Double Click? #--------------------------------------------------------------------------- def Input.mouse_double_click? @mouse_primary_dc[0] == 2 end #--------------------------------------------------------------------------- # * Mouse X Coordinate #--------------------------------------------------------------------------- def Input.mouse_x? @mouse_pos.nil? ? nil : @mouse_pos[0] end #--------------------------------------------------------------------------- # * Mouse Y Coordinate #--------------------------------------------------------------------------- def Input.mouse_y? @mouse_pos.nil? ? nil : @mouse_pos[1] end #--------------------------------------------------------------------------- # * Mouse Dragging? #--------------------------------------------------------------------------- def Input.mouse_dragging? return false if @mouse_rectdrag.nil? if @mouse_rectdrag.size >= 4 true else false end end #--------------------------------------------------------------------------- # * Mouse Drag Rect #--------------------------------------------------------------------------- def Input.mouse_drag_rect? return nil if @mouse_rectdrag.nil? if @mouse_rectdrag.size >= 4 if @mouse_rectdrag[0] <= @mouse_rectdrag[2] x = @mouse_rectdrag[0] width = @mouse_rectdrag[2] - @mouse_rectdrag[0] else x = @mouse_rectdrag[2] width = @mouse_rectdrag[0] - @mouse_rectdrag[2] end if @mouse_rectdrag[1] <= @mouse_rectdrag[3] y = @mouse_rectdrag[1] heigth = @mouse_rectdrag[3] - @mouse_rectdrag[1] else y = @mouse_rectdrag[3] heigth = @mouse_rectdrag[1] - @mouse_rectdrag[3] end Rect.new(x, y, width, heigth) else nil end end #--------------------------------------------------------------------------- # * Mouse Drag Coordinates #--------------------------------------------------------------------------- def Input.mouse_drag_coor? return nil if @mouse_rectdrag.nil? if @mouse_rectdrag.size >= 4 @mouse_rectdrag else nil end end #--------------------------------------------------------------------------- # * Add Combo #--------------------------------------------------------------------------- def Input.add_combo(params, restart_count, res_type, update = nil, id = nil) combo = Key_Combo.new(params, restart_count, res_type, update) if id.nil? if !@combos.has_key?(combo.id) id = combo.id else loop do id = rand(0xFFFF) break if !@combos.has_key?(id) end end else if @combos.has_key?(id) loop do id = rand(0xFFFF) break if !@combos.has_key?(id) end end end @combos[id] = combo return id end #--------------------------------------------------------------------------- # * Get All Combos #--------------------------------------------------------------------------- def Input.combos @combos end #--------------------------------------------------------------------------- # * Edit combos #--------------------------------------------------------------------------- def Input.combos=(new) @combos = new end #--------------------------------------------------------------------------- # * Delete Combo #--------------------------------------------------------------------------- def Input.delete_combo(id) @combos.delete(id) end #--------------------------------------------------------------------------- # * Delete Ended Combos #--------------------------------------------------------------------------- def Input.delete_ended_combos(ending = true) deleted = {} @combo.each_key do |c| if @combo[c].end? next if !@combo[c].true? == ending deleted[c] = @combo[c] @combos.delete© end end return deleted end end also I include a script from pokemon forum that creates a $width and $height variables that will control the game's screen size. CODE #================================================= ============================= # ■ Win32API #------------------------------------------------------------------------------ # by Squall squall@loeher.znn.com # Change the window size # I must thank cybersam for his mouse and keyboard scripts. they were very # useful finding some winapi function. # # !! this script MUST be on top of all other or the game will crash, # if you use scripts to enlarge maps! #================================================= =============================
class Win32API #-------------------------------------------------------------------------- # ● define constant #-------------------------------------------------------------------------- GAME_INI_FILE = ".\\Game.ini" # define "Game.ini" file HWND_TOPMOST = 0 # window always active HWND_TOP = -1 # window active when used only SWP_NOMOVE = 0 # window pos and sizes can be changed #-------------------------------------------------------------------------- # ● Win32API.GetPrivateProfileString // check your game title in Game.ini #-------------------------------------------------------------------------- def Win32API.GetPrivateProfileString(section, key) val = "\0"*256 gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l') gps.call(section, key, "", val, 256, GAME_INI_FILE) val.delete!("\0") return val end #-------------------------------------------------------------------------- # ● Win32API.FindWindow // find the RGSS window #-------------------------------------------------------------------------- def Win32API.FindWindow(class_name, title) fw = Win32API.new('user32', 'FindWindow', %(p, p), 'i') hWnd = fw.call(class_name, title) return hWnd end #-------------------------------------------------------------------------- # ● Win32API.SetWindowPos // change window positions and sizes #-------------------------------------------------------------------------- def Win32API.SetWindowPos(w, h) title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i') win = swp.call(hWnd, HWND_TOP, 150, 50, w + 6, h + 32, 0)
#the line below makes the window on top of all others #win = swp.call(hWnd, HWND_TOPMOST, 0, 0, w + 6, h + 32, SWP_NOMOVE) return win end #-------------------------------------------------------------------------- # ● Win32API.client_size // check the window width and height #-------------------------------------------------------------------------- def Win32API.client_size title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) rect = [0, 0, 0, 0].pack('l4') Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect) width, height = rect.unpack('l4')[2..3] return width, height end end
#================================================= ============================= # ■ proceed with creation of the window #------------------------------------------------------------------------------ # the width and height variables set the screen size. #================================================= ============================= $width = 640 $height = 580 win = Win32API.SetWindowPos($width, $height) if(win == 0) p "Size change has failed!" end
#Also, you have to add that script before the Main script in the list #================================================= ============================= # ■ Game_Player #------------------------------------------------------------------------------ # remade to be compatible with change sreen size script #================================================= =============================
class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● define constant #-------------------------------------------------------------------------- CENTER_X = ($width/2 - 16) * 4 # X coordinate in the center of the screen CENTER_Y = (($height-100)/2 - 16) * 4 # Y coordinate in the center of the screen end
#================================================= ============================= # ■ Spriteset_Map //squall@loeher.zzn.com #------------------------------------------------------------------------------ # remade to be compatible with change sreen size script #================================================= =============================
class Spriteset_Map #-------------------------------------------------------------------------- # ● Initialize #-------------------------------------------------------------------------- def initialize @viewport2 = Viewport.new(0, 0, $width, $height-100) @viewport3 = Viewport.new(0, 0, $width, $height-100) @viewport4 = Viewport.new(640, 0, $width-640, 480) @viewport5 = Viewport.new(0, 480, 640, $height-480) @viewport6 = Viewport.new(640, 480, $width-640, $height-580) @viewport1 = Viewport.new(0, 0, $width, $height-100)
@viewport2.z = 200 @viewport3.z = 5000
@tilemap = Tilemap.new(@viewport1) @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name) for i in 0..6 autotile_name = $game_map.autotile_names[i] @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name) end @tilemap.map_data = $game_map.data @tilemap.priorities = $game_map.priorities
@panorama = Plane.new(@viewport1) @panorama.z = -1000
@fog = Plane.new(@viewport1) @fog.z = 3000
@character_sprites = [] for i in $game_map.events.keys.sort sprite = Sprite_Character.new(@viewport1, $game_map.events[i]) @character_sprites.push(sprite) end @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
@weather = RPG::Weather.new(@viewport1)
@picture_sprites = [] for i in 1..50 @picture_sprites.push(Sprite_Picture.new(@viewport2, $game_screen.pictures[i])) end
@timer_sprite = Sprite_Timer.new
@tilemap2 = Tilemap.new(@viewport4) @tilemap2.tileset = RPG::Cache.tileset($game_map.tileset_name) @tilemap3 = Tilemap.new(@viewport5) @tilemap3.tileset = RPG::Cache.tileset($game_map.tileset_name) @tilemap4 = Tilemap.new(@viewport6) @tilemap4.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6 autotile_name = $game_map.autotile_names[i] @tilemap2.autotiles[i] = RPG::Cache.autotile(autotile_name) @tilemap3.autotiles[i] = RPG::Cache.autotile(autotile_name) @tilemap4.autotiles[i] = RPG::Cache.autotile(autotile_name) end
@tilemap2.map_data = $game_map.data @tilemap3.map_data = $game_map.data @tilemap4.map_data = $game_map.data
update end #-------------------------------------------------------------------------- # ● Dispose the sprite #-------------------------------------------------------------------------- def dispose
@tilemap.tileset.dispose @tilemap2.tileset.dispose @tilemap3.tileset.dispose @tilemap4.tileset.dispose
for i in 0..6 @tilemap.autotiles[i].dispose @tilemap2.autotiles[i].dispose @tilemap3.autotiles[i].dispose @tilemap4.autotiles[i].dispose end
@tilemap.dispose @tilemap2.dispose @tilemap3.dispose @tilemap4.dispose
@panorama.dispose @fog.dispose
for sprite in @character_sprites sprite.dispose end
@weather.dispose
for sprite in @picture_sprites sprite.dispose end
@timer_sprite.dispose @viewport1.dispose @viewport2.dispose @viewport3.dispose
@viewport4.dispose @viewport5.dispose @viewport6.dispose end #-------------------------------------------------------------------------- # ● Update the sprite #-------------------------------------------------------------------------- def update
if @panorama_name != $game_map.panorama_name or @panorama_hue != $game_map.panorama_hue @panorama_name = $game_map.panorama_name @panorama_hue = $game_map.panorama_hue if @panorama.bitmap != nil @panorama.bitmap.dispose @panorama.bitmap = nil end if @panorama_name != "" @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue) end Graphics.frame_reset end
if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue @fog_name = $game_map.fog_name @fog_hue = $game_map.fog_hue if @fog.bitmap != nil @fog.bitmap.dispose @fog.bitmap = nil end if @fog_name != "" @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue) end Graphics.frame_reset end
@tilemap.ox = $game_map.display_x / 4 @tilemap.oy = $game_map.display_y / 4 @tilemap.update
#if @tilemap.ox > $game_map.width * 32 - $width #@tilemap.ox = $game_map.width * 32 - $width #end #if @tilemap.oy > $game_map.width * 32 - $height #@tilemap.oy = $game_map.height * 32 - $height #end
@tilemap2.ox = @tilemap.ox + 640 @tilemap2.oy = @tilemap.oy @tilemap2.update
@tilemap3.ox = @tilemap.ox @tilemap3.oy = @tilemap.oy + 480 @tilemap3.update
@tilemap4.ox = @tilemap.ox + 640 @tilemap4.oy = @tilemap.oy + 480 @tilemap4.update
@panorama.ox = $game_map.display_x / 8 @panorama.oy = $game_map.display_y / 8
@fog.zoom_x = $game_map.fog_zoom / 100.0 @fog.zoom_y = $game_map.fog_zoom / 100.0 @fog.opacity = $game_map.fog_opacity @fog.blend_type = $game_map.fog_blend_type @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy @fog.tone = $game_map.fog_tone
for sprite in @character_sprites sprite.update end
@weather.type = $game_screen.weather_type @weather.max = $game_screen.weather_max @weather.ox = $game_map.display_x / 4 @weather.oy = $game_map.display_y / 4 @weather.update
for sprite in @picture_sprites sprite.update end
@timer_sprite.update
@viewport1.tone = $game_screen.tone @viewport1.ox = $game_screen.shake @viewport3.color = $game_screen.flash_color @viewport1.update @viewport3.update end end
class Game_Map #-------------------------------------------------------------------------- # ● Scroll the map down # distance : Distance to scroll in real units (4 = 1 pixel). #-------------------------------------------------------------------------- def scroll_down(distance) @display_y = [@display_y + distance, (self.height - ($height / 32.0)) * 128].min end #-------------------------------------------------------------------------- # ● Scroll the map left # distance : Distance to scroll in real units (4 = 1 pixel). #-------------------------------------------------------------------------- def scroll_left(distance) @display_x = [@display_x - distance, 0].max end #-------------------------------------------------------------------------- # ● Scroll the map right # distance : Distance to scroll in real units (4 = 1 pixel). #-------------------------------------------------------------------------- def scroll_right(distance) @display_x = [@display_x + distance, (self.width - ($width / 32.0)) * 128].min end #-------------------------------------------------------------------------- # ● Scroll the map up # distance : Distance to scroll in real units (4 = 1 pixel). #-------------------------------------------------------------------------- def scroll_up(distance) @display_y = [@display_y - distance, 0].max end end This will resize the screen at the time you start up the game. It can also be dynamically changed by using this code: CODE hWND_TOP = -1 #now expand game window $width =900 $height = 600 title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i') win = swp.call(hWnd, hWND_TOP, 40, 50, $width + 6, $height + 32, 0) CODE def return_screen hWND_TOP = -1 $width =640 $height = 580 title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i') win = swp.call(hWnd, hWND_TOP, 150, 50, $width + 6, $height + 32, 0) end
This post has been edited by puppeto4: May 24 2008, 07:45 AM
Reason for edit: Adding The Codebox
|
|
|
|
|
|
|
Posts in this topic
MCgamer Ultimate control: keyboard, mouse,input,bitmap,clipboard, and game screen Apr 6 2008, 01:59 AM Endzeit Holy crap thats long. I wish I could try this. Apr 6 2008, 02:04 AM fantasist Hm, I don't know how many features the Alework... Apr 6 2008, 10:29 AM MCgamer you are right about that, tons of add ons is a sli... Apr 6 2008, 12:05 PM fantasist RPG::Bitmap? Interesting, I'll take a peek
A... Apr 6 2008, 01:28 PM Blizzard This isn't just an keyboard and mouse input sc... Apr 7 2008, 03:54 AM Krenic-The-Hedgehog I wanted this for my F1 game! thank you!
o... Jul 9 2008, 12:21 AM
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
RPG RPG Revolution is an Privacy
Policy and Legal
|
|