Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Daniel Berger
RE: Posting and handling WM_* messages. [ reply ]  
2008-06-13 00:47
It looks like you've found your own solution. :)

Regards,

Dan

By: Bob Whiteside
RE: Posting and handling WM_* messages. [ reply ]  
2008-05-25 02:26
OK, continuing my blogging, I can send keys now!

I run this from a bash prompt, and I get a directory listing!

# WINUSERAPI
# BOOL
# WINAPI
# PostMessageW(
# __in_opt HWND hWnd,
# __in UINT Msg,
# __in WPARAM wParam,
# __in LPARAM lParam);

PostMessage = Win32API.new("user32", "PostMessageW", ['L'] * 4, 'L')
def send_keys(keys)
hwnd = GetForegroundWindow.Call
keys.each_byte { |k|
PostMessage.Call(hwnd, WM_CHAR, k, 0)
}
end

send_keys "ls\r"

By: Bob Whiteside
RE: Posting and handling WM_* messages. [ reply ]  
2008-05-25 01:07
OK, to follow up on my own post: No. I was not on the right track.

I spent time believing I needed to PostMessage or SendMessage a WM_MOUSEMOVE message. That's not what I wanted to do. I just wanted to call SetCursorPos(x, y).

Oh well. Next up: Sending kesystrokes and mouse clicks!

Here's what it looks like now. I'm inordinately pleased with these few lines. I think I'm an expert Windows programmer now, don't you?

SetCursorPos = Win32API.new("user32", "SetCursorPos", ['L'] * 2, 'L')
GetCursorPos = Win32API.new("user32", "GetCursorPos", ['P'], 'V')
def mousePos
lpPoint = " " * 8 # store two LONGs
GetCursorPos.Call(lpPoint)
lpPoint.unpack("LL") # get the actual values
end

def mm(x, y)
SetCursorPos.Call(x, y)
end

mm(100, 2)
puts mousePos

By: Bob Whiteside
Posting and handling WM_* messages. [ reply ]  
2008-05-22 00:37
Hi All,

I'd like to write a little robot to automate actions on the screen. I think I want to do this in Ruby (my latest favorite language), and the Win32 API thing looks to be what I need.

(Ya, I know, I should just buy/download one of the many available ones... it's a learning experience as much as anything.)

I'm wanting two things:
- How to send messages that do things like move the mouse, send keypress and mouse-up/down events, etc.
- A "record" mode in which I get to see and save away such messages for later replay.

Anyway, I'm asking for just a little help getting started. I think I've seen examples of how to call SendMessage (or is it PostMessage that I want?), and I'm starting to poke around at msdn, where I think I'll find the documentation of the windows api that I need. However,I can't see an example of how I'd hook the windows message loop so that I can record stuff, at least in Ruby using the Win32 api stuff.

Is this possible? Given my description of my goals, am I headed down the right path?

Thanks in advance for any responses. I realize I'm basically asking for some consulting help here. I'd gladly RTFM, if I only know where the FM is...

Cheers,
--Bob