manuelmayer-dev / Macro-Deck-Windows-Utils-Plugin

A collection of some useful functions for controlling Windows
MIT License
9 stars 14 forks source link

New Action: Switch Windows #7

Open manuelmayer-dev opened 2 years ago

manuelmayer-dev commented 2 years ago

Is your feature request related to a problem? Please describe. I would like to switch windows using an in-built action in MacroDeck2

Describe the solution you'd like An option in the Actions list to switch windows. It should be able to identify the window required full/partial string matches.

Describe alternatives you've considered I have considered using imprecise window switching by using Win+number, or alt-tab, or Win-tab. Doesn't quite work as well as precise window switching that I am envisioning.

Additional context Nothing of note.

gis-dur commented 2 years ago

Another alternative is to use the 'Windows Utils -> Command line command' like this: PowerShell (New-Object -ComObject WScript.Shell).AppActivate('Window Name here, can be partial') But this doesn't work when the target window is minimized. And, it would be nice to have the command executed in the background, as mentioned in #3

gis-dur commented 2 years ago

I've made a tiny Windows Console Program that will try its best to switch windows. It will search a window name by partial match, case insensitive. Use it from the 'Windows Utils -> Command line command' action like this: path-to-executable\AppActivateByWindowName.exe "some-partial-window-name" It's working pretty fine for me.

Sorry that I'm too lazy to check the GUI parts of the plugin. So instead of branching and pull-requesting, I decided to just attach my c++ source file here just for reference. Confirmed builds in Visual C++ 2022 (console application), 64-bit, Windows 10/11.

AppActivateByWindowName.zip

gis-dur commented 2 years ago

Updated. Now you can specify options like full/partial string matching. Use it from the 'Windows Utils -> Command line command' action. Example for full string match: path-to-executable\AppActivateByWindowName.exe /F "target-window-name"

The whole description:

Activates a window which name matches the given pattern string.

AppActivateByWindowName.exe [/I] [/P | /F | /S | /E | /R] <"string">

  /I        IGNORE CASE of the characters when matching.
  /P        PARTIAL mode. Matches if the pattern is partially in the window name.
  /F        FULL mode. Matches if the pattern is fully equal to the window name.
  /S        STARTS WITH mode. Matches if the pattern is in the beginning of the window name.
  /E        ENDS WITH mode. Matches if the pattern is in the end of the window name.
  /R        REGULAR EXPRESSION mode. Uses the pattern as a regular expression.
  "string"  Specifies the pattern to search for in a window name. Required.
  /?        Displays Help at the command prompt.

Default match mode is PARTIAL and CASE SENSITIVE.

The /I option can be combined with other options.
Other than that, only one of the matching modes can be specified.
If multiple modes are specified, only the first one is valid.

Only one pattern "string" can be specified.
If multiple "string"s are specified, only the first one is used to match.

My c++ source file, and also, the Windows Executable. AppActivateByWindowName.zip