Vagabond Lv.5
Age : 28 Inscrit le : 20/04/2009 Messages : 88
| Sujet: Détecter l'appuie d'une touche via un appel de script Sam 13 Juin 2009 - 9:29 | |
| Bonjour, J'ai un petit probleme : pour un évenement, j'ai besoin que pour le déclencher, on appuie sur Y. Mais quand je lance le jeu etque j'appuie sur S (donc Y sur VX), sa ne fait rien, et je sais pourquoi : c'est parce que j'utilise le script Input de Vlad nécessaire à l'ABS. J'aimerais trouver le moyen de mettre dans un évenement : - Code:
-
Condition : la Touche Y (S) est appuyée. J'arrive pas a trouver le moyen de faire sa. Merci de m'aider. - Code:
-
#============================================================================== # Input Module (Modificated by Vlad) #============================================================================== module Input Mouse_Left = 1 Mouse_Right = 2 Mouse_Middle = 4 Back = 8 Tab = 9 Enter = 13 Shift = 16 Ctrl = 17 Alt = 18 CapsLock = 20 Esc = 27 Space = 32 PGUP = 33 PGDN = 34 End = 35 Home = 36 Left = 37 Up = 38 Right = 39 Down = 40 PrintScreen = 44 Insert = 45 Delete = 46 Numberkeys = {} Numberkeys[0] = 48 Numberkeys[1] = 49 Numberkeys[2] = 50 Numberkeys[3] = 51 Numberkeys[4] = 52 Numberkeys[5] = 53 Numberkeys[6] = 54 Numberkeys[7] = 55 Numberkeys[8] = 56 Numberkeys[9] = 57 Letters = {} Letters["A"] = 65 Letters["B"] = 66 Letters["C"] = 67 Letters["D"] = 68 Letters["E"] = 69 Letters["F"] = 70 Letters["G"] = 71 Letters["H"] = 72 Letters["I"] = 73 Letters["J"] = 74 Letters["K"] = 75 Letters["L"] = 76 Letters["M"] = 77 Letters["N"] = 78 Letters["O"] = 79 Letters["P"] = 80 Letters["Q"] = 81 Letters["R"] = 82 Letters["S"] = 83 Letters["T"] = 84 Letters["U"] = 85 Letters["V"] = 86 Letters["W"] = 87 Letters["X"] = 88 Letters["Y"] = 89 Letters["Z"] = 90 LWin = 91 RWin = 92 Apps = 93 Numberpad = {} Numberpad[0] = 96 Numberpad[1] = 97 Numberpad[2] = 98 Numberpad[3] = 99 Numberpad[4] = 100 Numberpad[5] = 101 Numberpad[6] = 102 Numberpad[7] = 103 Numberpad[8] = 104 Numberpad[9] = 105 Multiply = 106 Add = 107 Subtract = 109 Decimal = 110 Divide = 111 Fkeys = {} Fkeys[1] = 112 Fkeys[2] = 113 Fkeys[3] = 114 Fkeys[4] = 115 Fkeys[5] = 116 Fkeys[6] = 117 Fkeys[7] = 118 Fkeys[8] = 119 Fkeys[9] = 120 Fkeys[10] = 121 Fkeys[11] = 122 Fkeys[12] = 123 NumLock = 144 ScrollLock = 145 LShift = 160 RShift = 161 LControl = 162 RControl = 163 LAlt = 164 RAlt = 165 Collon = 186 Equal = 187 Comma = 188 Underscore = 189 Dot = 190 Backslash = 191 Uncle = 192 LB = 219 Bar = 220 RB = 221 Quote = 222 @time = Array.new(256, 0) @press = Array.new(256, false) @trigger = Array.new(256, false) @repeat = Array.new(256, false) @release = Array.new(256, false) @dirs = [0, 0] InputInitialize = Win32API.new("Input", 'InputInitialize', 'LLLLLL', '') InputUpdate = Win32API.new("Input", 'InputUpdate', '', '') 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} DEFAULT_KEYS = {11=>[16,90],12=>[27,88,96],13=>[13,32],14=>[65],15=>[83], 16=>[68],17=>[81],18=>[87]} def convert_keys(key) begin keys = [] rkey = 'HKEY_CURRENT_USER\\Software\\Enterbrain\\RGSS' data = Registry.read_entry(rkey, 'ButtonAssign')[10, 25].scan(/./) 15.times {|i| keys.push(REG_KVALUES[i]) if key == data[i].unpack('C')[0]} keys rescue DEFAULT_KEYS[key] rescue [] end end module_function :convert_keys LEFT = 37 UP = 38 RIGHT = 39 DOWN = 40 A = convert_keys(11) B = [45] + convert_keys(12) C = convert_keys(13) X = convert_keys(14) Y = convert_keys(15) Z = convert_keys(16) L = [33] + convert_keys(17) R = [34] + convert_keys(18) SHIFT = 16 CTRL = 17 ALT = 18 F5 = 116 F6 = 117 F7 = 118 F8 = 119 F9 = 120 InputInitialize.call(@time.object_id, @press.object_id, @trigger.object_id, @repeat.object_id, @release.object_id, @dirs.object_id) def self.update InputUpdate.call end def self.trigger?(id) @trigger.indexes(*id.to_a).include?(true) end def self.press?(id) @press.indexes(*id.to_a).include?(true) end def self.triggerd?(what) if triggered.include?(what) return true end end def self.triggered array = Array.new @trigger.each_index {|i| array.push(i) if @trigger[i]} array end def self.pressed?(what) if pressed.include?(what) return true end end def self.pressed array = Array.new @press.each_index {|i| array.push(i) if @press[i]} array end def self.repeat?(id) @repeat.indexes(*id.to_a).include?(true) end def self.repeated array = Array.new @repeat.each_index {|i| array.push(i) if @repeat[i]} array end def self.release?(id) @release.indexes(*id.to_a).include?(true) end def self.released array = Array.new @release.each_index {|i| array.push(i) if @release[i]} array end def self.dir4 @dirs[0] end def self.dir8 @dirs[1] end
KEYS_NAMES = {1=>'Mouse Left',2=>'Mouse Right',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=>'PrintScreen',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'} def self.name?(id) return (KEYS_NAMES[id].nil? ? '???' : KEYS_NAMES[id]) end end
#----------------------------------------------------------------------------- module Registry module_function RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L') RegQueryValueExA = Win32API.new('advapi32', 'RegQueryValueExA','LPLPPP','L') HKEYS = {'HKEY_CLASSES_ROOT' => 0x80000000,'HKEY_CURRENT_USER' =>0x80000001, 'HKEY_LOCAL_MACHINE' => 0x80000002, 'HKEY_USERS' => 0x80000003, 'HKEY_CURRENT_CONFIG' => 0x80000005} 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') RegOpenKeyExA.call(hkey, key, 0, 131097, opened) opened = (opened + [0].pack('V')).unpack('V')[0] RegQueryValueExA.call(opened, entry, 0, type, 0, size) data = ' ' * (size + [0].pack('V')).unpack('V')[0] RegQueryValueExA.call(opened, entry, 0, type, data, size) 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 end |
|