From: Colin Bartlett Date: 2010-04-17T01:45:19+09:00 Subject: Re: How to use AutoIt in Ruby On Wed, Apr 14, 2010 at 10:07 PM, James Britt wrote: > Marvin Gülker wrote: >> ... Otherwise, stick to win32ole: >> require "win32ole" >> au3 = WIN32OLE.new("AutoItX3.Control") > > That's how I've used it.  It's pretty straightforward. > > I typically ended up writing a few helper methods for some of the repetitive > things that required sending multiple commands to autoitx, or just to make > the main code cleaner. Yes: I've found it useful to wrap AutoIt#Send to allow multiple sending multiple keystrokes with waiting periods between each "bunch" of keystrokes. WinModule::AutoIt = = WIN32OLE.new( "AutoItX3.Control" ) # send_keys( "cc", 1.5, "kty" ) sends "cc", sleeps 1.5 seconds, sends "kty" def send_keys( *args ) args = args[ 0 ] if args.size == 1 && args[ 0 ].kind_of?( Array ) args.each do | arg | case arg when String then AutoIt.Send( arg ) when Numeric then if ! ( defined?( Complex ) && arg.kind_of?( Complex ) ) then sleep arg end end end end Other examples are here http://gist.github.com/368632 which has some stuff which doesn't need Autoit, and other stuff for which AutoIt is not needed but for which *I* need AutoIt because I have not yet found out how to do it without AutoIt. For example this MsgBox code works in JRuby 1.4 and Ruby 1.8.6 but (it seems) not in Ruby 1.9.1 (at least not for me!): User32_MsgBox = User32[ 'MessageBoxA', 'ILSSI' ] result, = User32_MsgBox.call(0, text, title, buttons + icon + modality) So if anyone knows how to use "dl" and Win32API.new( 'user32', 'SendInput', 'IPI', 'I' ) to send keystrokes (or can pop up a MsgBox in Ruby 1.9.1) I'd be very interested to see how. > It's also handy to learn about the Windows message queue and sending > commands there.  It makes it easier/more reliable to trigger actions using, > say, accelerator commands or keyboard shortcuts (e.g. ctrl+v) instead of > mouse clicks or menu navigation. ... > http://www.autoitscript.com/autoit3/docs/appendix/WinMsgCodes.htm That's a useful thought and link. Thanks.