Jump to content

_WinAPI_PostMessage() question


Recommended Posts

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

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 by MilesAhead
Link to comment
Share on other sites

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

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 by MilesAhead
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...