Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 14:18

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Help with Postmessage, Sending keystrokes.. !

Discussion on Help with Postmessage, Sending keystrokes.. ! within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
avati's Avatar
 
elite*gold: 0
Join Date: Oct 2007
Posts: 431
Received Thanks: 1,574
Question Help with Postmessage, Sending keystrokes.. !

Hello everyone ,
i use this sourcecode that i found for sending keys on a minimized window.
Code:
; #FUNCTION# ====================================================================================================================
; Name...........: SimulKey
; Description ...: Simulate a Key-Send to a specified handle in the Background
; Author ........: Felix Lehmann
; Modified.......: If you modify this Script, please enter your name here
; Remarks .......: -
; Related .......: -
; Parameters ....: $hwnd = Specified Window to Send to
; ...............: $key = Key or String to Send (If String $string have to be enabled [see $string])
; ...............: $string = Set this to 1 If your "$key" is a string
; ...............: $state = Set this to 'up' or 'down' if u want a special event | Default is press the Key 1 Time
; ...............: $delay = The delay to hold the key down
; Return Values .: 1 = Done | -1 = Couldn't load user32.dll
; Link ..........; -
; ===============================================================================================================================
Func SimulKey($hWnd, $key, $string = 0, $state = 'skip', $delay = 10)
	;//Open DLL (user32)
	$user32 = DllOpen('user32.dll')
	If $user32 = -1 Then
		SetError(-1, 1, -1)
	EndIf

	;//Handle Special Keys
	Switch StringLower($key)
		Case 'enter'
			$WM_ENTER = 0x0d
			$dCall = DllCall($user32, 'int', "MapVirtualKey", 'int', $WM_ENTER, 'int', 0)
			$lParam = BitOR(BitShift($dCall[0], -16), 1)
		Case 'space'
			$WM_SPACE = 0x20
			$dCall = DllCall($user32, 'int', "MapVirtualKey", 'int', $WM_SPACE, 'int', 0)
			$lParam = BitOR(BitShift($dCall[0], -16), 1)
		Case 'tab'
			$WM_TAB = 0x09
			$dCall = DllCall($user32, 'int', "MapVirtualKey", 'int', $WM_TAB, 'int', 0)
			$lParam = BitOR(BitShift($dCall[0], -16), 1)
			;//Handle Standard Keys
		Case Else
			;//Stringmode 1
			If $string = 1 Then
				$split = StringSplit($key, "")
				For $ctn = 1 To $split[0]
					$split[$ctn] = Asc(StringLower($split[$ctn]))
				Next
				For $ctn = 1 To $split[0]
					$dCall = DllCall($user32, 'int', "VkKeyScan", 'int', $split[$ctn])
					$lParamAsc = DllCall($user32, 'int', "MapVirtualKey", 'int', $dCall[0], 'int', 0)
					$lParam = BitOR(BitShift($lParamAsc[0], -16), 1)
					$lUpParam = BitOR($lParam, 0xC0000000)
					DllCall($user32, 'int', "PostMessage", 'hwnd', $hWnd, 'int', $WM_KEYDOWN, 'int', $dCall[0], 'int', $lParam)
					Sleep($delay)
					DllCall($user32, 'int', "PostMessage", 'hwnd', $hWnd, 'int', $WM_KEYUP, 'int', $dCall[0], 'int', $lUpParam)
					Sleep(100)
				Next
				;//Stringmode 0
			ElseIf $string = 0 Then
				$key = Asc(StringLower($key))
				$dCall = DllCall($user32, 'int', "VkKeyScan", 'int', $key)
				$lParamAsc = DllCall($user32, 'int', "MapVirtualKey", 'int', $dCall[0], 'int', 0)
				$lParam = BitOR(BitShift($lParamAsc[0], -16), 1)
			EndIf
	EndSwitch
	$lUpParam = BitOR($lParam, 0xC0000000)
	If $string = 0 Then
		Switch StringLower($state)
			Case 'skip'
				DllCall($user32, 'int', "PostMessage", 'hwnd', $hWnd, 'int', $WM_KEYDOWN, 'int', $dCall[0], 'int', $lParam)
				Sleep($delay)
				DllCall($user32, 'int', "PostMessage", 'hwnd', $hWnd, 'int', $WM_KEYUP, 'int', $dCall[0], 'int', $lUpParam)
			Case 'down'
				DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", $WM_KEYDOWN, "int", $dCall[0], "int", $lParam)
			Case 'up'
				DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", $WM_KEYUP, "int", $dCall[0], "int", $lParam)
		EndSwitch
	EndIf
	DllClose($user32)
	Return 1
EndFunc   ;==>SimulKey
I dont use the normal SEND function of the autoit because it is blocked.(the reason why is blocked doesnt matter)
The problem is that the function works perfect only for sending specific keys.
I can send every character.
I canot send function keys "F1 - F12".
Right,left,up,down keys doesnt work also.
And combination keystrokes like ALT+F4, shift+` and so goes on.
Please, can anyone modify this code so to works for the above situations?
Or if you having any example with a working function that will be great.
Thanks in advance...
avati is offline  
Old 04/11/2011, 07:55   #2
 
HardCore.1337's Avatar
 
elite*gold: 1
Join Date: Feb 2009
Posts: 1,726
Received Thanks: 729
try with ASCII Code
HardCore.1337 is offline  
Old 04/11/2011, 17:36   #3
 
derpo's Avatar
 
elite*gold: 0
Join Date: Feb 2010
Posts: 344
Received Thanks: 151
Did you try ControlSend? Maybe this is unpatched.
derpo is offline  
Old 04/11/2011, 18:08   #4
 
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
Is it for Archlord? I've tested my UDF with Archlord and it works:
KDeluxe is offline  
Old 04/11/2011, 21:34   #5
 
avati's Avatar
 
elite*gold: 0
Join Date: Oct 2007
Posts: 431
Received Thanks: 1,574
Quote:
Originally Posted by HardCore.1337 View Post
try with ASCII Code
I tried any kind of method.
Converted the functions to ascii and i sended with the same parameters that i took from spy ++. Until now no success.
For some strange reason the keys that only works perfect are the keys that use $WM_KEYDOWN and $WM_KEYUP.
I changed the code and i added $WM_SYSKEYDOWN and $WM_SYSKEYUP, for some keys that use that parameters.
i made also a code that sends only one key every time with the parameters that i take from spy++.
It works ok for every character key but when i use it for functions keys like F10, or to send combination keys like ctrl+` , the operation fail.

Quote:
Originally Posted by KillerDeluxe View Post
Is it for Archlord? I've tested my UDF with Archlord and it works:
The problem is not that i can not send keys at all. The problem is that i canot send specific keys like the one below.
Have you tried to send F10? Or alt+f4 or ctrl+` ????
If your code works for those keys you save me....
I am waiting for your feedback...
avati is offline  
Old 04/12/2011, 00:13   #6
 
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
PHP Code:
#include <PostMessage.au3>

$hWnd WinGetHandle("[CLASS:RwAppClass]")
;
$hWnd "Archlord"

;===> F10
_PostMessage_Send
($hWnd"F10")

;===> 
Ctrl F4
_PostMessage_Send
($hWnd"{LCTRL DOWN}")
Sleep(50)
_PostMessage_Send($hWnd"F4")
_PostMessage_Send($hWnd"{LCTRL UP}"
I can't test the Ctrl + F4 combination but it works for another game which is protected by XTrap.
KDeluxe is offline  
Old 04/12/2011, 09:42   #7
 
avati's Avatar
 
elite*gold: 0
Join Date: Oct 2007
Posts: 431
Received Thanks: 1,574
Quote:
Originally Posted by KillerDeluxe View Post
PHP Code:
#include <PostMessage.au3>

$hWnd WinGetHandle("[CLASS:RwAppClass]")
;
$hWnd "Archlord"

;===> F10
_PostMessage_Send
($hWnd"F10")

;===> 
Ctrl F4
_PostMessage_Send
($hWnd"{LCTRL DOWN}")
Sleep(50)
_PostMessage_Send($hWnd"F4")
_PostMessage_Send($hWnd"{LCTRL UP}"
I can't test the Ctrl + F4 combination but it works for another game which is protected by XTrap.
i will give it a try ... thanks mate , i will post my results...

EDIT:
The same results with the UDF i use.
NO SUCCESS. Can anyone try to send F10 or ctrl + ` on Archlord window???
Thanks in advance
avati is offline  
Reply


Similar Threads Similar Threads
Simulating Keystrokes
11/18/2011 - General Gaming Releases - 6 Replies
Hi folks, usually I am not releasing my stuff. But here is a small hint for "do it yourself" people, how to simulate keystrokes for Warhammer Online. The usual way to do that via Postmessage or kbdevent does NOT work here, because Warhammer is a DirectInput game. It cost me some hours to figure out a proper but easy way how to do it: INPUT input;
Aion 1.9.0.3 sending keystrokes in background mode
08/29/2010 - Aion - 1 Replies
Hello to all! I'am trying to send keystrokes in BACKGROUND MODE to AION client using C++ (Builder2009): I do it like that: ... PostMessage(Window,WM_KEYDOWN, VK_OEM_MINUS, 0x00020001); ... This function works good for me, but as i can see i can't send WASD or VK_MENU(ALT) and more, something like game protection
The difference between hard/software keystrokes
02/17/2009 - 9Dragons - 2 Replies
Hi all, I recently joined so forgive my noobies questions I was wondering how Keystrokes made by software and hardware are different. The reason for this the "Logitech Revolution mouse" can asign other Keys to it's Buttons even keyboad keys how come Gameguard allows this? Does Gameguard only block what it knows or is this only partly the case?
How can i send keystrokes to an application in background
04/09/2008 - Archlord - 3 Replies
i need something like a macro that can send keystrokes to an application in background and loop the sending in delay of 2 minutes or something... Any1 have an idea how can i do this or where can i download such program?
Verschiedene Arten um Keystrokes zu simulieren?
08/04/2007 - General Coding - 9 Replies
Hi, hat irgendwer Ahnung was für verschiedene Möglichkeiten es gibt Tastendrücke an ne andere Applikation zu testen? Also, welche Funktionen werden von den ganzen Makro Tools benutzt? Mich wundert es halt, dass GameGuard z.B. so tools wie Synergy oder das MakroTeil der G15 ignoriert, aber auf der anderen Seite funktioniert das N52 einwandfrei. Da muss es also unterschiede geben....



All times are GMT +1. The time now is 14:18.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.