Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 11:51

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

Advertisement



Finding the problem with this code...

Discussion on Finding the problem with this code... within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2005
Posts: 116
Received Thanks: 28
Finding the problem with this code...

Hi,

i was trying something basic with this code but it does not seem to work and i would like to know if any experienced people with AutoIT and user32.dll could help me out...

i found this code in this forums and was trying to send "o down and up" to notepad basic getting it is handle using the window title.

I DO realise that there is SEND and CONTROLSEND but that does not solve my problem it has to be with user32.dll

Thanks for any help.

Code:
#include <WindowsConstants.au3>

Local $user32 = DllOpen("user32.dll")
Global $hwnd = WinGetHandle("Notepad - Edit1")

KeySend("o", "down")
Sleep(2000)
KeySend("o", "up")
DllClose($user32)

; send single keyboard event to non active window
; event = pressed, down, up
; kdown = key down delay
; note: supports only lower case keys + NUMx, Fx, some special keys and @
Func KeySend($inkey, $evt ="pressed", $kdown = 50)
	; handling for special keys
	Switch StringUpper($inkey)
	Case "@"
		$skey = 0x40
		$lparam = 0x00100001
		DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", 0x71, "long", $lparam)
		DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_CHAR, "int", $skey, "long", $lparam)
		Sleep(20)
		DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", 0x71, "long", BitOR($lparam, 0xC0000000)) 
		Case "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"
			$skey = 0x6f + Int(StringMid($inkey, 2)) 
			ContinueCase
		Case "NUM0", "NUM1", "NUM2", "NUM3", "NUM4", "NUM5", "NUM6", "NUM7", "NUM8" , "NUM9"
			if StringUpper(StringLeft($inkey, 3)) = "NUM" Then
				$skey = 0x60 + Int(StringMid($inkey, 4)) 
			EndIf
			ContinueCase
		Case "RETURN", "SPACE", "TAB", "BACK", "END", "HOME", "SNAPSHOT", "INSERT", "DELETE", "LEFT", "RIGHT", "UP", "DOWN"
			Switch StringUpper($inkey)
				Case "RETURN"
					$skey = 0x0D
				Case "SPACE"
					$skey = 0x20
				Case "TAB"
					$skey = 0x09
				Case "BACK"
					$skey = 0x08
				Case "END"
					$skey = 0x23
				Case "HOME"
					$skey = 0x24
				Case "SNAPSHOT"
					$skey = 0x2c
				Case "INSERT"
					$skey = 0x2d
				Case "DELETE"
					$skey = 0x2e
				Case "LEFT"
					$skey = 0x25
				Case "RIGHT"
					$skey = 0x27
				Case "UP"
					$skey = 0x26
				Case "DOWN"
					$skey = 0x28
			EndSwitch
			$ret = DllCall($user32, "int", "MapVirtualKey", "int", $skey, "int", 0)
			$lparam = BitShift($ret[0], -16)
			$lparam = BitOr($lparam, 1)
			DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
			Sleep($kdown)
			DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
		Case Else ; default lower case key handling
			$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)
		Select
			Case $evt = "pressed"
				DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
				Sleep($kdown)
				DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
			Case $evt = "down"
				DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
			Case $evt = "up"
				DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
		EndSelect 
	EndSwitch
EndFunc

; create long int (32 bit) from 2 short int (16 bit) 
Func MakeLong($LoWord, $HiWord)
	Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
namedrisk is offline  
Old 10/16/2009, 19:47   #2


 
buFFy!'s Avatar
 
elite*gold: 1826
Join Date: Mar 2009
Posts: 4,310
Received Thanks: 6,287
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
buFFy! is offline  
Reply


Similar Threads Similar Threads
i got a problem with finding a item, stored in npc
08/01/2010 - Kal Online - 6 Replies
yeah... my problem is this: i tryed to make a easy shophack on a pserver with following tut that was really easy to understand 6. Put at "Value type" > "Arrey Of Bytes" At the "16-bit , 32-bit , All" << PRESS ON ALL Vink the box at "Hyper search" 7. Now search this value : 3600370055005600BD 8. You got 1 address, Right Mouse on the address and press "Browse this memory Region" 9. You see a new window, Upper Section & The Below Section We are going to use the BELOW section ONLY
Finding code
07/12/2010 - General Gaming Discussion - 1 Replies
i need the code for import images in a script(in autoitv3), The idea is that the script search a picture and make an action if it finds. thx
vb.net - problem im code
03/16/2010 - .NET Languages - 2 Replies
Hey Leute Um mich ein bisschen in XNA und Visual Basic umzuschauen hab ich versucht das Platform Game - Beispiel von C# XNA Game Studio zu übersetzen (gibt im inet en übersetzer, is recht leicht weil ja beide codes in einen gleichen zwischencode übersetzt werden beim compilieren) so, nun hab ich alle klasen übersetzt und hinzugefügt, zeigt auch keine fehler an außer bei einer Zeile: Imports System Imports Microsoft.Xna.Framework Imports Microsoft.Xna.Framework.Graphics Namespace...
problem-finding and updating CE Offsets
11/03/2009 - Dekaron - 2 Replies
Hey guys, Ive checked the 2moons exploit hacks and stuff and i used the tutorial how to find and update the offsets using Cheat engine by using Array of bytes and the Value of the hack..and i get a new address.so far so good. Now the problem is when i open Cheat engine(the updates file which i got the scripts of the hacks in,Just need to update offsets) and i do edit Script.once i change the Adress i try to save but the file is being saved as a CEA file,and i don't know how to open it. The...
help needed about code finding
07/26/2008 - RF Online - 7 Replies
I have a question about CE. When ever people say that you need to look for this code like for example A8 08 and replace them with 00 00 isnt it that you will find this code in a middle of other codes like this?: XX XX XX XX XX XX XX XX XX 00 00 00 00 00 8F 00 65 78 98 65 43 32 56 87 65 09 00 99 77 66 55 44 43 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 98 76 54 98 78 65 45 87 A8 08 00 00 00 00... and so on and so forth...



All times are GMT +2. The time now is 11:52.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

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