ru2cool Posted April 4, 2012 Share Posted April 4, 2012 I am working on a project for my job and have run into a small snag. I need the program to send TAB & SHIFT + TAB to a hidden window. The following code works flawlessly for sending just TAB - #include <WinAPI.au3> #include <WindowsConstants.au3> $window = HWnd(0x002D05D8) _WinAPI_PostMessage($window, $WM_KEYDOWN, 0x09, 0) _WinAPI_PostMessage($window, $WM_KEYUP, 0x09, 0) However, when I try to add in the SHIFT key the program still only sends TAB. Example below - #include <WinAPI.au3> #include <WindowsConstants.au3> $window = HWnd(0x002D05D8) _WinAPI_PostMessage($window, $WM_KEYDOWN, 0x10, 0) _WinAPI_PostMessage($window, $WM_KEYDOWN, 0x09, 0) _WinAPI_PostMessage($window, $WM_KEYUP, 0x09, 0) _WinAPI_PostMessage($window, $WM_KEYUP, 0x10, 0) Any assistance with this would be greatly appreciated. Link to comment Share on other sites More sharing options...
ru2cool Posted April 5, 2012 Author Share Posted April 5, 2012 /bump Link to comment Share on other sites More sharing options...
JohnOne Posted April 5, 2012 Share Posted April 5, 2012 Have you considered trying ControlSend()? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MilesAhead Posted April 5, 2012 Share Posted April 5, 2012 (edited) If JoneOne's suggestion doesn't work I would try SendMessage rather than PostMessage provided you have verified the window exists and you know it will respond. PostMessage doesn't wait for the message to be handled. Conceivably the message to hold shift down could be processed after the tab key message. Better to somehow actually change the state of the shift key if the regular Send and ControlSend don't work. I also avoid SendMessage when PostMessage will do the job just because it avoids potential hangs. But if you need to guarantee the order of processing the messages you need to use SendMessage. Edited April 5, 2012 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
ru2cool Posted April 6, 2012 Author Share Posted April 6, 2012 Thank you both very much for the information. @JohnOne - I never thought of using ControlSend() to target the window itself but that actually worked perfectly. Example code below - $window = HWnd(0x008A043A) ControlSend($window, "", $window, "{TAB}") Sleep(1000) WinSetState($window, "", @SW_SHOW) WinActivate($window) Sleep(2000) WinSetState($window, "", @SW_HIDE) ControlSend($window, "", $window, "+{TAB}") Sleep(1000) WinSetState($window, "", @SW_SHOW) WinActivate($window) Sleep(2000) WinSetState($window, "", @SW_HIDE) @MilesAhead - I tried using the _SendMessage() function but it would still only send the TAB key. For the sake of learning, I would very much like to figure out how to send keys using both of those functions. If you are willing, I would be grateful for any further assistance. Example code below - #include <SendMessage.au3> #include <WindowsConstants.au3> $window = HWnd(0x008A043A) _SendMessage($window, $WM_KEYDOWN, 0x10, 0) _SendMessage($window, $WM_KEYDOWN, 0x09, 0) _SendMessage($window, $WM_KEYUP, 0x09, 0) _SendMessage($window, $WM_KEYUP, 0x10, 0) Link to comment Share on other sites More sharing options...
MilesAhead Posted April 7, 2012 Share Posted April 7, 2012 My #1 suggestion when learning is check the function return codes and error codes such as @error. I have no interest in banging my head against someone else's trial and error brick wall. It's work. If you want to learn do your own lifting. My Freeware Page Link to comment Share on other sites More sharing options...
ru2cool Posted April 7, 2012 Author Share Posted April 7, 2012 Thank you for being honest. Link to comment Share on other sites More sharing options...
MilesAhead Posted April 7, 2012 Share Posted April 7, 2012 (edited) Thank you for being honest.You're welcome. JohnOne's approach is better. Sometimes it's a more productive use of time to abandon infeasible methods. Although a stubborn streak can be good for debugging, this language being a macro language it's not likely you will surpass the way it's done internally in a short time. Keep pluggin' away. Edited April 7, 2012 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
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