Sign in to follow this  
Followers 0
GrungeRocker

Sending a Key to a minimized Window

14 posts in this topic

Hey folks!

I'm searching for a way to send a Key to a minimized window.

So I thought of Posting the WM_KEYDOWN message to the handle and then after a small sleep sending WM_KEYUP

So I ended up with this code:

$hWnd = WinGetHandle("Window title")
Sleep(2000)
$ret = DllCall("user32.dll", "int", "MapVirtualKey", "int", Asc("w"), "int", 0)
If IsArray($ret) Then
    DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", Asc("w"), "long", _Long(1, $ret[0]))
    Sleep(500)
    DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", Asc("w"), "long", _Long(1, $ret[0]) + 0xC0000000)
EndIf

Func _Long($LoW, $HiW)
    Return BitOR(($HiW*0x10000), BitAND($LoW, 0xFFFF))
EndFunc

Links to the functions:

MapVirtualKey: http://msdn.microsoft.com/de-de/ms646306(en-us,VS.85).aspx

PostMessage: http://msdn.microsoft.com/de-de/ms644944(en-us,VS.85).aspx

And the WM-messages I need:

#define WM_KEYDOWN 256
#define WM_KEYUP 257

(Taken form winuser.h)

Hope anyone can help and tell me an other way or my mistake


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@grungeRocker

_SendMessage function with $VM_CHAR for hexadecimal keys like _IsPressed

Look at #Include <SendMessage.au3>

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

I'm sorry, but I just can't find that include...

And maybe I should mention, that I need it for moving in a game, so it is necessary, sending WM_KEYDOWN and WM_KEYUP


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

It is entirely likely that your game "knows" when it is minimized and ignores input on purpose... You may have no solution.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

Hm no...

It doesn't even work, if the window of the game is active....

So there must be something wrong -.-


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

did this?

ControlSend("title","","","<keystroke here>")

Or...

$hwnd = WinGetHandle("title")

ControlSend("title","",$hwnd,"<keystroke here>")

just curious what your attempts have been...


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

" Sending a Key to a minimized Window, ControlSend() won't work"


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

" Sending a Key to a minimized Window, ControlSend() won't work"

well... you outskill me... so I guess I've helped all I can.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

i have the same problem until I created a topic sends number 1 but the magic does not function and when I open chat I see I number it 1 being typed

Share this post


Link to post
Share on other sites

i have the same problem until I created a topic sends number 1 but the magic does not function and when I open chat I see I number it 1 being typed

I don't get your post oO


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

Alot of games have various protection against things like this.

Not to discourage you, but out of experience I can tell you your probably S.O.L.

Share this post


Link to post
Share on other sites

Hm... This game is not protected against memory writing...

So you can easily Teleport and fly....

But it should be protected against messages, sent by an other program?

Man there must be a way to do it :)


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

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