I wonder if anyone knows how to use Win32 to automate a keystroke using Ruby?
+3
A:
I recommend checking out Ian Dees' Scripted GUI Testing With Ruby. This example of sending keystrokes to a Windows program comes from the book's 2nd chapter. The supporting script is available here.
# START:typing
"this is some text".upcase.each_byte do |b| #<callout id="co.upcase"/>
keybd_event.call b, 0, KEYEVENTF_KEYDOWN, 0
sleep 0.05
keybd_event.call b, 0, KEYEVENTF_KEYUP, 0
sleep 0.05
end
# END:typing
I highly-recommend this book for anyone doing platform-specific, or cross-platform GUI automation and testing.
Duncan Beevers
2009-07-24 16:26:30