Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby/DL SendInput

Reply
Thread Tools

Ruby/DL SendInput

 
 
Peter C. Verhage
Guest
Posts: n/a
 
      05-08-2005
Hi,

I want to use Ruby/DL to call the Win32 user32.dll SendInput method
(http://tinyurl.com/jrxm). Unfortunately this method takes some complex
arguments; several nested structs, including a union and a pointer to an
array of a certain struct etc. How can I use Ruby/DL to call this method?

Regards,

Peter
 
Reply With Quote
 
 
 
 
Logan Capaldo
Guest
Posts: n/a
 
      05-09-2005
On 5/8/05, Peter C. Verhage <> wrote:
> Hi,
>
> I want to use Ruby/DL to call the Win32 user32.dll SendInput method
> (http://tinyurl.com/jrxm). Unfortunately this method takes some complex
> arguments; several nested structs, including a union and a pointer to an
> array of a certain struct etc. How can I use Ruby/DL to call this method?
>
> Regards,
>
> Peter
>
>


Did you try the Win32API module?

You code would look something like this:

require 'Win32API'

sendInput = Win32API.new("user32", "SendInput", ['I', 'P', 'I'], 'I')

# you'll have to pack the INPUT string in the appropiate manner
input = some_array.pack(some_fmt)

sendInput.call(num_inputs, input, sizeofINPUT)



 
Reply With Quote
 
 
 
 
Ryan Leavengood
Guest
Posts: n/a
 
      05-09-2005
Logan Capaldo wrote:
>
> Did you try the Win32API module?
>
> You code would look something like this:
>
> require 'Win32API'
>
> sendInput = Win32API.new("user32", "SendInput", ['I', 'P', 'I'], 'I')
>
> # you'll have to pack the INPUT string in the appropiate manner
> input = some_array.pack(some_fmt)
>
> sendInput.call(num_inputs, input, sizeofINPUT)


I tried this when I saw the original email, but couldn't get it to work.
Mapping those funky Windows types is tricky. But anyhow, here is the
(non-working) code:

require 'Win32API'

SendInput = Win32API.new("user32", "SendInput", ['I','P','I'], 'I')
GetLastError = Win32API.new("kernel32", "GetLastError", [], 'L')

INPUT_MOUSE = 0
INPUT_KEYBOARD = 1
INPUT_HARDWARE = 2

KEYEVENTF_EXTENDEDKEY = 0x0001
KEYEVENTF_KEYUP = 0x0002
KEYEVENTF_SCANCODE = 0x0003

# The Left and Right Windows keys
VK_LWIN = 0x5B
VK_RWIN = 0x5C

def send_key(key)
keyboard_input = [INPUT_KEYBOARD, key[0], 0, 0, 0, 0].pack('LCCLLL')
SendInput.call(1, keyboard_input, keyboard_input.size())
end

res = send_key('R')
puts "Got result: #{res}"
puts "GetLastError: #{GetLastError.call}"
__END__

If anyone gets this working, I'd like to hear about it.

Ryan


 
Reply With Quote
 
Nospam
Guest
Posts: n/a
 
      05-09-2005
Ryan Leavengood wrote:
> If anyone gets this working, I'd like to hear about it.


Thanks for the responses / example code. Will try and see if I can get
this to work this evening. Will keep you posted.

Regards,

Peter
 
Reply With Quote
 
Takaaki Tateishi
Guest
Posts: n/a
 
      05-09-2005
Peter C. Verhage wrote:
> I want to use Ruby/DL to call the Win32 user32.dll SendInput method
> (http://tinyurl.com/jrxm). Unfortunately this method takes some complex
> arguments; several nested structs, including a union and a pointer to an
> array of a certain struct etc. How can I use Ruby/DL to call this method?


I successfully called SendInput to take a screen snapshot via ruby-dl2-0.6.
A program I used is available at the following URL.

http://rubyforge.org/cgi-bin/viewcvs...ype=text/plain

Regards,
--
Takaaki Tateishi <>



 
Reply With Quote
 
Peter C. Verhage
Guest
Posts: n/a
 
      05-09-2005
Takaaki Tateishi wrote:
> I successfully called SendInput to take a screen snapshot via ruby-dl2-0.6.
> A program I used is available at the following URL.


Code looks great! Seems really easy to map the C types to Ruby. Is there
a binary version available for the One-Click-Installer (Ruby 1.8.x)? I
tried the various ZIP files of Ruby-DL 2.0.6 but one needs MingW and the
other one needs Cygwin.

Thanks,

Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SendInput() inconsistency between 32/64 bit function equivalents =?Utf-8?B?TWFrc2lt?= Windows 64bit 5 02-12-2010 03:55 PM
How do I use SendInput in Python? Adam W. Python 1 02-16-2008 11:45 PM
SendInput Problems Jamie Turner Windows 64bit 5 02-13-2007 06:12 PM
Problems with GenerateConsoleCtrlEvent and SendInput mike_cole@adaptec.com Perl Misc 10 11-10-2005 11:34 PM
SendInput too slow Barb C++ 1 10-03-2003 02:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57