brotherhobbes Posted November 17, 2005 Posted November 17, 2005 I have a simple little .au3 that sends a keypress to the active window after an interval. Is there a more elegant way to Send() a keypress to a specified window without losing focus in whatever window you have up currently? doing: WinSetState("name", "", @SW_RESTORE) WinWaitActive("name") then sending the key is annoying, to say the least.
Valuater Posted November 17, 2005 Posted November 17, 2005 look at ControlSend() in help... like this help has very good demo's at the bottom of each page on your computer press the following Start > All Programs > Autoit v3 > Autoit Help File when that loads then press the "search" tab then type in "?your search?" and press "List Topics" **** you can do this with any word you want thats what i do all the time 8)
brotherhobbes Posted November 17, 2005 Author Posted November 17, 2005 (edited) Valuater said: look at ControlSend() in helpThanks, ControlSend() looks like what I was searching for. And hey, amazingly enough, when I was reading about Send(), ControlSend() was in the related links at the bottom.It probably looks like I don't use the help file, but I live in there. Searching for things like "application" and "focus" was not bringing up the right topics, though.thanks again.edit: Alright. Guess you can't use ControlSend() if the window doesn't have a control. Using AU3Info.exe and the window is coming up with blanks on, Control ID, ClassNameNN, Text. Edited November 17, 2005 by brotherhobbes
herewasplato Posted November 17, 2005 Posted November 17, 2005 brotherhobbes said: ...can't use ControlSend()...Tell us more about the application that you are attempting to send stuff to and there might be another suggestion that we can offer. [size="1"][font="Arial"].[u].[/u][/font][/size]
Valuater Posted November 17, 2005 Posted November 17, 2005 herewasplato said: Tell us more about the application that you are attempting to send stuff to and there might be another suggestion that we can offer.i agree with that..also with just 11 posts we can see you tried... you put some effort into it..sothats the kind of people we enjoy helping8)
brotherhobbes Posted November 18, 2005 Author Posted November 18, 2005 Well most of those posts were from last year when I first started playing with AutoIt. Everyone here has always been helpful in pointing to the function I just couldn't find or the variable I kept forgetting to set - AutoItSetOption("SendAttachMode", 1) comes to mind. The issue at hand. My little brother plays a mage in this game called World of Warcraft. Part of his job as a mage type in this game is to conjure up magical water for other people to drink, this process involves him sitting there tapping a single key on the keyboard for twenty minutes to a hour before he can actually start playing. He hates this endless key tapping. What's worse is that if he shuts the game off for fifteen minutes, his mindless key presses of magical water disappears and he has to do it all over again. So I wrote him a "push a button for me for awhile so I can just read a book" script. Something like: While 1 If ShouldThisBeRunNow = 1 Then Send(Keypress) Sleep(Awhile) EndIf Wend It works fine, problem is now it's not good enough for a "push a button for me for awhile so I can just read a book." Now he wants a "push a button for me for awhile so I can look at webpages." ControlSend() works great if you have a control that you can send to. Edit1 in Notepad, for example. What about windows that do not have a control? Specifically, trying to just send a keypress to this World of Warcraft game without it having focus, but you can see similar behavior with cmd.exe.
herewasplato Posted November 18, 2005 Posted November 18, 2005 I'm not sure that you can get there from here... see the last post here:http://www.autoitscript.com/forum/index.ph...2&st=0&p=122507You might want to start a new thread with World of Warcraft and/or WOW in the subject line.There are a lot of members that might help - I do not have the game.later... [size="1"][font="Arial"].[u].[/u][/font][/size]
brotherhobbes Posted November 18, 2005 Author Posted November 18, 2005 herewasplato said: I'm not sure that you can get there from here... see the last post here:http://www.autoitscript.com/forum/index.ph...2&st=0&p=122507well that looks like a start. a couple people said they couldn't get that code to work with WOW, but i'll mess with it. if i can get this sending keypresses to notepad or cmd then it might transfer over.is this the proper format? i think i'd need the find the hex for keyboard key down and also for key up. 0x0060 should be Numpad0, unless i looked it up incorrectly.DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle("Untitled - Notepad"), "int", HexForKeyDown, "int", 0x0060)DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle("Untitled - Notepad"), "int", HexForKeyUp, "int", 0x0060)Anyone have an idea where I could find the hex for keyboard key down and up?
brotherhobbes Posted November 19, 2005 Author Posted November 19, 2005 shamless bump. hoping someone can either point me to a msdn page or point out how i'm using DllCall wrong. also, does anyone know where i could get a list for the hex values for things like keyboard key down and keyboard key up? all the lists i found did not have this.
PhB Posted November 24, 2005 Posted November 24, 2005 (edited) brotherhobbes said: shamless bump.hoping someone can either point me to a msdn page or point out how i'm using DllCall wrong. also, does anyone know where i could get a list for the hex values for things like keyboard key down and keyboard key up? all the lists i found did not have this.$WM_KEYDOWN=0x100$WM_KEYUP=0x101 Decimal Hex Virtual Key Code Key Counterpart ------- --- ---------------- --------------- 8 08 VK_BACK Backspace 9 09 VK_TAB Tab 13 0D VK_RETURN Enter (either one) 16 10 VK_SHIFT Shift (either one) 17 11 VK_CONTROL Ctrl (either one) 18 12 VK_MENU Alt (either one) 19 13 VK_PAUSE Pause 20 14 VK_ESCAPE Esc 32 20 VK_SPACE Spacebar 33 21 VK_PRIOR Page Up 34 22 VK_NEXT Page Down 35 23 VK_END End 36 24 VK_HOME Home 37 25 VK_LEFT Left Arrow 38 26 VK_UP Up Arrow 39 27 VK_RIGHT Right Arrow 40 28 VK_DOWN Down Arrow 44 2C VK_SNAPSHOT Print Screen 45 2D VK_INSERT Insert 46 2E VK_DELETE Delete 48-57 30-39 None 0 to 9 on main keyboard 65-90 41-5A None A to Z 96-105 60-69 VK_NUMPAD0 to VK_NUMPAD9 Numeric Keypad 0 to 9 w/ Num Lock ON 106 6A VK_MULTIPLY Numeric Keypad * 107 6B VK_ADD Numeric Keypad + 109 6D VK_SUBTRACT Numeric Keypad - 110 6E VK_DECIMAL Numeric Keypad . 111 6F VK_DIVIDE Numeric Keypad / 112-121 70-79 VK_F1 to VK_F10 Function Keys F1 to F10 122-135 7A-87 VK_F11 to VK_F24 Function Keys F11 to F24 144 90 VK_NUMLOCK Num Lock 145 91 VK_SCROLL Scroll LockBTW I'm also making a bot, not for WoW though, and I've found this topic while I was also searching for hints on sending events to minimized windows. I'll let you know if I find something usefull. Edited November 24, 2005 by PhB
Moderators SmOke_N Posted November 24, 2005 Moderators Posted November 24, 2005 You could try ControlSend() without a control ID, that works from time to time. ControlSend("My Game Title", "", "", "Key you want to send") Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
PhB Posted November 24, 2005 Posted November 24, 2005 (edited) ronsrules said: You could try ControlSend() without a control ID, that works from time to time. ControlSend("My Game Title", "", "", "Key you want to send") Hum nope, ControlSend doesn't seems to work with special chars, e.g ^e doesn't send CTRL-e, at leat for me I'm trying to build a _SendPlus with special char parsing. As for now it looks like this, but it's not functionning 100%. Perhaps I should have learned how to program Windows instead of sticking on Unix EDIT: changing WM_KEYDOWN to WM_CHAR for special cars makes ENTER key working, side effect is that it's pops up iconified window (although it doesn't focus on it so it should be ok). One side note for games: SendMessage() doesn't work if game is using DirectInput. I have some luck using a game in which you can explicitly disable DirectInput Maybe it's not the case on WoW... EDIT2: works better with 0x prefix for standard chars expandcollapse popupFunc _SendPlus($Window, $text = "") Local $WM_KEYDOWN = 0x0100 Local $WM_KEYUP = 0x0101 Local $WM_CHAR = 0x0102 Local $VK_BACK = 0x08 Local $VK_TAB = 0x09 Local $VK_RETURN = 0x0d Local $VK_SHIFT = 0x10 Local $VK_CONTROL = 0x11 Local $VK_MENU = 0x12 Local $VK_PAUSE = 0x13 Local $VK_ESCAPE = 0x14 Local $VK_SPACE = 0x20 Local $VK_PRIOR = 0x21 Local $VK_NEXE = 0x22 Local $VK_END = 0x23 Local $VK_HOME = 0x24 Local $VK_LEFT = 0x25 Local $VK_UP = 0x26 Local $VK_RIGHT = 0x27 Local $VK_DOWN = 0x28 Local $VK_SNAPSHOT = 0x2c Local $VK_INSERT = 0x2d Local $VK_DELETE = 0x2e Local $i = 0 Local $loc = 0 Local $key = 0 Local $op = "" Local $string = StringSplit($text, "") MsgBox(0,"chaine",$text) For $i = 1 to $string[0] If $string[$i] = '{' Then $loc = $i ElseIf $string[$i] = '}' Then $spec = StringMid($text,$loc,$i - $loc + 1) $op = $WM_CHAR Select Case $spec = "{ENTER}" $key = $VK_RETURN Case $spec = "{SHIFT}" $key = $VK_SHIFT Case $spec = "{SHIFTDOWN}" $key = $VK_SHIFT $op = $WM_KEYDOWN Case $spec = "{SHIFTUP}" $key = $VK_SHIFT $op = $WM_KEYUP Case $spec = "{CTRL}" $key = $VK_CONTROL Case $spec = "{CTRLDOWN}" $key = $VK_CONTROL $op = $WM_KEYDOWN Case $spec = "{CTRLUP}" $key = $VK_CONTROL $op = $WM_KEYUP Case $spec = "{ESCAPE}" $key = $VK_ESCAPE Case $spec = "{SPACE}" $key = $VK_SPACE Case $spec = "{INSERT}" $key = $VK_INSERT Case Else If $string[$loc + 2] = ' ' Then ; single car with repetitions or up/down $key = "0x" & _StringToHex($string[$loc + 1]) Else MsgBox(0,"Error","Unknown cmd *" & $text & "*") EndIf EndSelect DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle($Window), _ "int", $op, _ "int", $key, _ "long", 1) $loc = 0 ElseIf $loc > 0 Then ContinueLoop Else $key = "0x" & _StringToHex($string[$i]) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle($Window), _ "int", $WM_CHAR, _ "int", $key, _ "long", 1) EndIf Next EndFunc Edited November 24, 2005 by PhB
PhB Posted November 24, 2005 Posted November 24, 2005 I've modified function to behave somewhat like Send(). Seems to work quite well, BUT ESCAPE for instance doesn't work. Any clue ?
qingtianyu9 Posted December 18, 2006 Posted December 18, 2006 good nice,thanks,i'll used to a game,haha!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now