Sign in to follow this  
Followers 0
karamazov

User32.dll Issues with sending "Ctrl" key

8 posts in this topic

Hey everyone. I have been playing around with the windows API in order to try and get auto it to send clicks/keystrokes to a hidden window. I have managed to send mouse clicks to the hidden window, and also I have managed to send alpha numeric characters to the window. However, I am having some trouble with sending some different keys. I am trying to send the control key twice, followed by a letter. Here is my code:

Func sendCommand()
     $key = "0x" & _StringToHex("o")

     _minSend("Notepad", "0x0100", "0x11")
     _minSend("Notepad", "0x0100", "0x11")
     _minSend("Notepad", "0x0102", $key)

endfunc

Func _minSend($window, $state, $keys)
            DllCall("user32.dll", "int", "SendMessage", _
                "hwnd",  WinGetHandle($window), _
                "int",   $state, _
                "int",   $key, _
                "long",  1)
EndFunc

When I run that the control keys are not sent, but strangely the "g" key is. Maybe there is some special thing that I have to do to get a control key to send, that I don't know about? I have managed to send the enter button, so there is apparently no problem in sending keys that are not alphanumeric to the window. I have tried lots of stuff, like sending control down, up, down, up and control down, down, up, up and none of those worked. Help please :)

karamazov

Share this post


Link to post
Share on other sites



Trust me I would be using control send if I could. The window is a game so no controls to be found. And I am trying to send the keys to a minimized window in sort of background mode style as to not interrupt whatever the user is currently doing.

They virtual key value is correct so I'm not sure whats wrong with my function. Maybe if you could expand on the "... it's a bit more...", that would be helpful.

Share this post


Link to post
Share on other sites

Well I tried the beta version...Control send does work with blank ID, but it still does not send the ctrl key :\. For example:

ControlSend("Notepad", "", "", "{LCTRL}")

ControlSend("Notepad", "", "", "{LCTRL 2}")

ControlSend("Notepad", "", "", "{CONTROL}")

None of those do anything. I am assuming now that there is something different that you must do in order for the control key to work. Thanks for the help thusfar.

Share this post


Link to post
Share on other sites

Well I tried the beta version...Control send does work with blank ID, but it still does not send the ctrl key :\. For example:

ControlSend("Notepad", "", "", "{LCTRL}")

ControlSend("Notepad", "", "", "{LCTRL 2}")

ControlSend("Notepad", "", "", "{CONTROL}")

None of those do anything. I am assuming now that there is something different that you must do in order for the control key to work. Thanks for the help thusfar.

But these keys wouldn't do anything in notepad would they?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Well no I'm just using notepad as an example... :).

I have verified that pressing control twice actually does something.

One guess I have is that you might have to use a different method to send multiple keystrokes of the "ctrl" key using controlsend of user32.dll. Or I could be completely wrong...

Share this post


Link to post
Share on other sites

Func sendCommand()
     $key = "0x" & _StringToHex("o")

     _minSend("Notepad", "0x0100", "0xA2")
     _minSend("Notepad", "0x0100", "0xA2")
     _minSend("Notepad", "0x0102", $key)

endfunc

Func _minSend($window, $state, $keys)
            DllCall("user32.dll", "int", "SendMessage", _
                "hwnd",  WinGetHandle($window), _
                "int",   $state, _
                "int",   $key, _
                "long",  1)
EndFunc

Try that (Untested Code Warning)

Share this post


Link to post
Share on other sites

Hmm.. no luck with that one either.

Share this post


Link to post
Share on other sites

Sorry for the double post...Bump...anyone have any other ideas? This problem has stumped me :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0