Sign in to follow this  
Followers 0
namedrisk

user32.dll to send key

1 post in this topic

#1 ·  Posted (edited)

Hi,

i have been searching around this forum and while i found MANY topics talking about this and with examples ... most of the example were broken and would not even work anymore maybe because it was too old or and auotit has gone thru many updates ...

Anyway... i did like to know if any one could point me or help me out with a simple good example of user32.dll sending key to the notepad in background...

I do realise that there is SEND and CONTROLSEND but for what i need, send and controlsend does not work properly i have tried it in many ways and it seems to bug when i use shift, control and a few other keys while the game is minimized or not on focus. I did made a post about this but i could not find a solution so i am moving to user32.dll

Since when the game is not active it does not receive keys with user32.dll i have a chance that it may works just fine.

I've been trying it but i am not shure on how to send the keys ... for example

#include <WindowsConstants.au3>

Global $user32 = DllOpen("user32.dll")
Global $WindowName = "Sem título - Bloco de notas" ; name of the window of notepad in my version of windows
KeySend("o", $WindowName)
DllClose($user32)

Func KeySend($inkey,$hwnd)
   $key = DllCall($user32, "int", "VkKeyScan", "int", Asc(StringLower($inkey)))
   $skey = $key[0] 
   $ret = DllCall($user32, "int", "MapVirtualKey", "int", $skey, "int", 0)
   $lparam = BitShift($ret[0], -16)
   $lparam = BitOr($lparam, 1)
   DllCall($user32, "int", "PostMessage", "hwnd", WinGetHandle($hwnd), "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
   Sleep(2000)
   DllCall($user32, "int", "PostMessage", "hwnd", WinGetHandle($hwnd), "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
EndFunc

this code i found here in the forums it is not my own...

Edited by namedrisk

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