Ruby/DL SendInput

Discussion in 'Ruby' started by Peter C. Verhage, May 8, 2005.

  1. 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
    Peter C. Verhage, May 8, 2005
    #1
    1. Advertising

  2. On 5/8/05, Peter C. Verhage <-nonsense.org> 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)
    Logan Capaldo, May 9, 2005
    #2
    1. Advertising

  3. 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
    Ryan Leavengood, May 9, 2005
    #3
  4. Peter C. Verhage

    Nospam Guest

    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
    Nospam, May 9, 2005
    #4
  5. 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/viewcv...AD&cvsroot=dlcookbook&content-type=text/plain

    Regards,
    --
    Takaaki Tateishi <>
    Takaaki Tateishi, May 9, 2005
    #5
  6. 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
    Peter C. Verhage, May 9, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Barb

    SendInput too slow

    Barb, Oct 3, 2003, in forum: C++
    Replies:
    1
    Views:
    1,819
    Thomas Matthews
    Oct 3, 2003
  2. Adam W.

    How do I use SendInput in Python?

    Adam W., Feb 16, 2008, in forum: Python
    Replies:
    1
    Views:
    632
    Gabriel Genellina
    Feb 16, 2008
  3. Replies:
    0
    Views:
    211
  4. anne001
    Replies:
    1
    Views:
    428
  5. Replies:
    10
    Views:
    870
Loading...

Share This Page