This guide was written a long time ago for users to interact with apps written for Windows 10 and below, using the base controls/menus/etc.
While it may work with some apps, it's highly likely it will not work with more recent apps due to more modern systems in place, i.e. custom controls, apps written in Electron, Windows 11 being antisocial, etc.
In short, don't expect it to work as the chances are very high that it won't.
Here's a quick guide to using Spy++* to find the PostMessage
code to open the 'About' window of Notepad - bearing in mind that it can also be used for a large number of other applications (providing they support it), this includes, but isn't restricted to, sending button presses to media players, opening specific menu items without having to navigate them first, the list goes on...
Simply put, PostMessage
allows Windows objects to communicate with each other - for example, using the mouse to click on an app menu item basically triggers a message that the app interprets as a uniquely numbered UI item being activated and responds by showing that menu item's window, or similar effect - using PostMessage
we can send the same message directly, completely bypassing the need for any mouse interaction at all.
*I use Microsoft Spy++ as it's literally the only software I could find that still works! The downside is that it only ships with Visual Studio so I don't know what the legal standing is for sharing that software as a stand-alone app (so don't ask me for it). I can say that there's a copy on GitHub (five versions actually) if you know your way around a search engine (v14!)
With that out of the way, let's get straight in and fire up Notepad and the version of Spy++ relevant to your OS...
Note: Bear in mind that the toolbar buttons change depending on the active window.
First, we need to hook Spy++ into Notepad, so click the fifth icon along (window + binoculars) and you'll open the Find Window panel.
Click and drag the cross-hair symbol from this panel over Notepad's titlebar and let go.
Now that we've locked on, make sure 'Messages' is selected on the bottom and click OK.
Note: You might see a lot of stuff going on in this window; don't panic, we're going to sort that now...
Maximise this 'Messages' window and click on the seventh icon ('Logging Options', to the right of the traffic light, looks like an app window)...
Message Options:
Make sure everything in the Windows tab is unchecked except 'Save Settings as Default'.
On the Messages tab, click 'Clear All' to ensure 0 messages selected shows, then scroll through the 'Messages to View' panel until you get to WM_COMMAND (~4/5ths down) and select it, making sure that's the only message selected. Again, tick 'Save Settings as Default'.
Finally, on the Output tab, uncheck everything aside from 'Decoded Message Parameters' and 'Save Settings as Default' and 'OK' out of there.
As this might be your first time, if there's anything in the messages window you should clear it now so we can start fresh with the new settings.
As soon as you activate Notepad you'll see two lines pop up in Spy++, you can ignore these for now as they're SendMessages and not what we want, you can tell by the second parameter being an 'S' - we're looking for a 'P', for PostMessage of course...
Click 'Help > About Notepad'...
And there it is!
There's a line which is noticeably different from the rest with a 'P' for the second parameter:
16CHR_HEX_STRING P WM_COMMAND wNotifyCode:0 (sent from a menu) wID:65
^This was sent by PostMessage!
The PostMessage parameters that we'll need from this, as listed in the docs, are:
PostMessage Msg,wParam,lParam,,WinTitle
Msg
is WM_COMMAND but that's not an AHK variable so we need to use its hex code instead:0x111
.wParam
is the number we got with wID:65
.lParam
is the number we got with wNotifyCode:0
.WinTitle
is something you should know already by now or you're reading the wrong guide...
Anyway, let's plug those values in:
PostMessage 0x111,65,0,,ahk_exe Notepad.exe
Now run it, and... there it is!
I'm going to have to save the Bluetooth trick itself for another guide as this one has taken it out of me over the last three days (",)