From: Heesob Park Date: 2009-12-30T15:30:42+09:00 Subject: Re: au3 0.1.1 released Hi, 2009/12/29 Marvin Gülker : > Thank you, Edward, that helped me out a lot. :) > My code now looks like this (to simplify this for the moment, I sticked > to the non-unicode variant): > --------------------------------- > #Encoding: UTF-8 > require "win32/api" > GetLastError = Win32::API.new("GetLastError", '', 'I', "kernel32") > SendInput = Win32::API.new("SendInput", 'IPI', 'I', "user32") > #Needed for the KEYBDINPUT struct's last parameter > GetMessageExtraInfo = Win32::API.new("GetMessageExtraInfo", '', 'P', > "user32") > INPUT_KEYBOARD = 1 > KEY_A = 0x41 > #KEYEVENTF_UNICODE = 0x0004 > > input = [ >  INPUT_KEYBOARD, >  KEY_A, >  0, >  0, >  0, >  GetMessageExtraInfo.call > ].pack('issiiP') > > #While the program pauses, I click into an editor window > #to see wheather I get the 'a' or not. > sleep 3 > > SendInput.call(1, input, input.size) > p GetLastError.call > --------------------------------- > I'm using Ruby 1.9.1-p243 at the moment (will update to -p376 soon), but > I've checked that Array#pack returns a BINARY-encoded string, so there > shouldn't occur a problem. Nevertheless, I get error code 87, what means > "One of the parameters was invalid.". I suppose it's the C array I don't > provide, even if it contains only one element. Do you know how to build > up one? > For Future Reference, here is a working code. -------------------------------------------------------------------------- #Encoding: UTF-8 require "win32/api" GetLastError = Win32::API.new("GetLastError", '', 'I', "kernel32") SendInput = Win32::API.new("SendInput", 'IPI', 'I', "user32") #Needed for the KEYBDINPUT struct's last parameter GetMessageExtraInfo = Win32::API.new("GetMessageExtraInfo", '', 'P', "user32") INPUT_KEYBOARD = 1 KEY_A = 0x0061 # unicode for 'a' cf. 0x00E4 for 'ä' KEYEVENTF_UNICODE = 0x0004 KEYEVENTF_KEYUP = 0x0002 #While the program pauses, I click into an editor window #to see wheather I get the 'a' or not. sleep 3 #key down input = [ INPUT_KEYBOARD, 0, KEY_A, KEYEVENTF_UNICODE, 0, nil ].pack('issiiP') + 0.chr * 8 # 8bytes dummy to make 28bytes SendInput.call(1, input, input.size) # key up input = [ INPUT_KEYBOARD, 0, KEY_A, KEYEVENTF_UNICODE|KEYEVENTF_KEYUP, 0, nil ].pack('issiiP') + 0.chr * 8 SendInput.call(1, input, input.size) ---------------------------------------------------------------- Regards, Park Heesob