From: "Marvin Gülker" Date: 2009-12-29T18:35:14+09:00 Subject: Re: au3 0.1.1 released Edward Middleton wrote: > Marvin Gülker wrote: >> So, if you could help me out with #pack and #unpack, especially with >> structs in structs (I would look for an example from the WinAPI, if you >> want) I would start working on that again. >> > > I haven't used Win32API, I just connected directly from dl. Examples of > the functions/structs you were having problems with would help. > > Edward OK - SendInput() is the main function to simulate keyboard and mouse input: http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx (from there you can also get to the descriptions of INPUT and KEYBDINPUT) It takes the size of a C array containing INPUT structs, a C array containing INPUT structs and the size of an INPUT structure. The INPUT struct itself wants a description wheather it is a keyboard or a mouse struct, and depending on that it chooses the MOUSEINPUT oder KEYBDINPUT struct from its second, an union, parameter. I tried with keyboard simulation first, so I have to build up the KEYBDINPUT struct: That takes a virtual key code describing the key to simulate - unless you want to simulate unicode characters -, than an unicode character as a WORD if you want to simulate a unicode char. Next parameter is the input simulation type, e.g. unicode, followed by a time stamp and a pointer to extra message info. That isn't as complicated as it sounds, but there are some problems I cannot get around. First, how to obtain the size of the INPUT structure? There's no sizeof keyword in Ruby... Second, how to transform a unicode char (Windows usually uses UTF-16LE I've found out when working on au3) into a WORD? As far as I know, this is an integer value, but a unicode char like ä consists of more than one byte? Third, as said, how to pack a struct into a struct, in this example: How to pack the KEYBDINPUT into the INPUT struct? And last but not least, how to build up a C array in Ruby? That said, my quite incomplete code looks like this: ------------------------------------ SendInput = Win32::API.new("SendInput", 'IPI', 'I', "user32") INPUT_KEYBOARD = 1 #We're using keyboard simulation KEYEVENTF_UNICODE = 0x0004 #We want to simulate unicode chars #INPUT struct: LP #KEYBDINPUT struct: IILLP keybdinput = [0, "a".encode("UTF16-LE").pack('I'), KEYEVENTF_UNICODE, 0, nil].pack('IILLP') input = [INPUT_KEYBOARD, keybdinput].pack('LP') #Yes, I know that the following line produces more than one error. SendInput.call(1, [input], ??) #How to obtain the size of an INPUT? ------------------------------------- Marvin -- Posted via http://www.ruby-forum.com/.