Jump to content

sneding keystroke(not mouseclick) to inactive window


Tiggus
 Share

Recommended Posts

Hi all,

New AutoIt user here, and I have to say I have been missing out. Of course no one posts just to say everything is fine, so now down to business.

I am attempting to send a series of keystrokes to a inactive window, which I do not wish to gain focus on. I have the WinHandle for the window in question, and if I use ControlFocus it works just fine. Doing some digging everyone seems to refer people with this problem to Insolence's UDF here: http://www.autoitscript.com/forum/index.ph...c=7112&st=0.

This is great, it is what I want to do, EXCEPT it is mouse clicks and not keystrokes. I am not a windows programmer so I am not familiar with user32.dll and how I would need to modify this code to send "F1" for instance, instead of a mouse click.

Can anyone help?

Link to comment
Share on other sites

To send a keystroke to a specific window, I believe you can use ControlSend, but I don't know if the window will stay inactive when you do that.

To send a key like F1, put it in curvy brackets like so: {F1}

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

To send a keystroke to a specific window, I believe you can use ControlSend, but I don't know if the window will stay inactive when you do that.

To send a key like F1, put it in curvy brackets like so: {F1}

Yes ControlSend will send the key fine, once the window has focus. I am trying to send to a minimized window which I do not wish to gain focus at all.

I just had a bit of luck with google, and found some messages that indicate it should be possible using a dllcall, now if I could figure out the exact syntax I would be in business. See below:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CHAR = &H102

SendMessage hwnd, WM_CHAR, KeyCode, 0

Link to comment
Share on other sites

  • Moderators

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CHAR = &H102

SendMessage hwnd, WM_CHAR, KeyCode, 0

http://www.autoitscript.com/forum/index.ph...&pid=291260

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you! I now have it sending keys to my minimized window!

However I am at a loss as to what "keycode" F1-F12 would be. When I go to MSDN and lookup the Virtual scan code table it says F1 should be 70. However when I send the following it sends the letter 'F'.

Global $WM_CHAR = 0x0102

SendMessage($winhandle,$WM_CHAR, 70, 0);

Func SendMessage($hwnd, $msg, $wp, $lp)

Local $ret

$ret = DllCall("user32.dll", "long", "SendMessageA", "long", $hwnd, "long", $msg, "long", $wp, "long", $lp)

Return $ret[0]

EndFunc

Link to comment
Share on other sites

Sorry let me clarify this a bit.

Const $VK_F1 = 0x70

SendMessage($hwnd,$VK_F1);

Func SendMessage($hwnd,$wp)

Local $ret

Local $lp = 0;

$ret = DllCall("user32.dll", "long", "SendMessageA", "long", $hwnd, "long", $WM_CHAR, "long", $wp, "long", 0)

Return $ret[0]

EndFunc

Sends the character "p" to my window. Although 0x70 is listed as virtual key F1 on all the references I could find.

Ideas?

Link to comment
Share on other sites

ControlSend will do PostMessages in release 3.2.3 .. Jon said it. Im looking for send keystrokes to inactive too. Now im waiting for new release.

Good look until dont have new release.

I can send to inactive windows fine. The problem is sending F1-F12.

Wading my way through the help files I discovered as usual most of this work was already done for me, it was just a matter of finding it. I am now down to:

#Include <Misc.au3>

Const $WM_CHAR = 0x0102

Const $VK_F1 = 0x70

_SendMessage($hwnd, $WM_CHAR, $VK_F1,0)

If @error Then

MsgBox(0,"", "_SendMessage Error: " & @error)

Exit

EndIf

But instead of F1, I get "p". If I substitute 0x31 as my hex value I get "1" as expected.

Link to comment
Share on other sites

Hey, I'm just wondering (don't have autoit on my laptop), does your example actually work without having to gain focus on the window? Or is the window forced to gain focus before it can send the text?

Sorry for the offtopic-like question, but I'm curious.

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Hey, I'm just wondering (don't have autoit on my laptop), does your example actually work without having to gain focus on the window? Or is the window forced to gain focus before it can send the text?

Sorry for the offtopic-like question, but I'm curious.

Kurt

It works without gaining focus, yep.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...