views:

30

answers:

2

Hello,

I´ve been trying to interact with another app on windows, which doesn´t have any data exchange protocol implemented. So i figured the best way to do this is by fetching data from an app and send it to the other one by sending keystrokes, simulating human interaction.

But i am having such a hard time trying to implement this kind of behavior! Do you know how to do this using Ruby?

thanks a lot!

+1  A: 

You could install the Ruby-FFI gem: [sudo] gem install ffi, use it to load user32.dll, then bind and call the keybd_event method.

Here's an example from the FFI Github wiki:

require 'ffi'

module Win
  VK_VOLUME_DOWN = 0xAE;   VK_VOLUME_UP = 0xAF;   VK_VOLUME_MUTE = 0xAD;   
  KEYEVENTF_KEYUP = 2

  extend FFI::Library
  ffi_lib 'user32'
  ffi_convention :stdcall

  attach_function :keybd_event, [ :uchar, :uchar, :int, :pointer ], :void

  # simulate pressing the mute key on the keyboard
  keybd_event(VK_VOLUME_MUTE, 0, 0, nil);
  keybd_event(VK_VOLUME_MUTE, 0, KEYEVENTF_KEYUP, nil);

end
ikezue
just what i needed!
Lucas d. Prim
+1  A: 

keybd_event would work, you could also use jruby to script the java Robot class

rogerdpack
i've never played around with java =/ think i am gonna try ffi first.. Thanks a lot anyway! :)
Lucas d. Prim