autohotkey - SetTitleMatchMode, RegEx match all windows not working - windows-10

I'm trying to create a shortcut to activate the bottom-most window, where the cursor is pointing. In the screenshot below, we have 3 windows placed one on top of the other. When I press Ctrl-d, it should activate the last window at the back. Because the mouse cursor goes through all 3 windows.
This is what I have coded so far,
^d::
; (1) this works
; SetTitleMatchMode, 2
; WinActivateBottom, Notepad2; Activate the least recent window
return
(1) this works perfectly, when I specify the window title "eg. Notepad2".
^d::
; (2) make it work with all windows (DOES NOT WORK)
SetTitleMatchMode, RegEx
WinActivateBottom, .* ; Activate the least recent window
return
(2) this does not work. I'm trying to make it work with ANY windows regardless of the window title. Is WinActivateBottom explicitly not allowing RegEx?

Related

Autohotkey: problem with minimizing windows

I create two windows through autohotkey and move them to my leftmost and rightmost monitor respectively (I have 3 monitors).
When I minimize them, and call them again, they are being shown on the central monitor. But I want them to be shown where they were before.
See following gif.
Following is the ahk script:
Run, Notepad
WinWait, ahk_class Notepad
WinSetTitle, asd
Run, Notepad
Sleep, 1000
WinGet, fensterID, List, ahk_class Notepad
Loop, %fensterID% { ; will run loop for number of windows in array
WinActivateBottom, % "ahk_id " fensterID%A_Index%
WinGetTitle, title, A
MsgBox, %title%
if (title == "asd")
WinMove A,, 1500, 0
else
WinMove A,, -2304, 0
WinMaximize, A
}
Meanwhile I switched to AutoIt and - having the same problem there - I found out, thanks also to this, that it works if I disable the maximized option for Windows Terminal (the actual program I was trying out with), then move and maximize the window. It should do the same with AutoHotKey.

How to move cursor automatically from code editor to terminal in VS Code

I am using Microsoft VS Code version 1.34.0 (64 bit version) on Windows 10 64 bit.
I have "Python" and "Code Runner" extensions installed and using it for Python 3.7.3
I click on triangle in top right corner to run code or do Ctrl + Alt + N.
When I run code that needs user input, I can see the message(if provided any in code) and cursor in Terminal but the cursor is inactive (empty rectangle).
The active cursor (blinking) is still in code editor pane.
Is there any way to automatically move the active cursor from code editor to Terminal for user input?
I am trying to avoid one extra mouse click or (Ctrl + `)
Install Code Runner from vscode extensions
Then Add the following line in settings.json :
"code-runner.preserveFocus": false

Sublime Text 3 - split windows at launch

Running Windows and Sublime Text (3.1.1 Build 3176) for the last few days, every time I launch the editor it starts with one window split into two panes. This happens whether I
launch from a command prompt with 'subl';
launch form the window menu; or
select a file from the file manager and edit it
It never remembers that I have set it back to a single pane with Alt-Shift 1. I cannot find a setting to change this behaviour.
Help pls

Changing focus with Autohotkey, what is going on?

I just want my script to select the right Window to input key storkes. To do this I think I use WinActivate. I ran the example from their site but found some strange results in Windows 10
IfWinExist, Untitled - Notepad
WinActivate ; use the window found above
else
WinActivate, Calculator;
If Notepad is minimized, it gets the focus
If Notepad is open but is not have the focus (i.e. another window is on top of it), Notepad gets the focus
If Notepad is not open and the calculator is minimized, for some strange reason it doesn't get the focus.
If Notepad is not open and the calculator is open but not have the focus, it gets the focus.
What is causing the inconsistency?
It happens because of the implementation of the WinActivate function on the language. WinActivate tries to open an window, but it might not be able to.
From the documentation
Six attempts will be made to activate the target window over the
course of 60ms. Thus, it is usually unnecessary to follow WinActivate
with WinWaitActive or IfWinNotActive.
Usually you can try the #WinActivateForce directive in combination with WinWaitActive or IfWinNotActive.
Sometimes you can use an ahk_exe parameter to match the window. It may work in cases where the window title doesn't. In this case you would use
Also it's useful to try restoring the window with WinRestore.
SetTitleMatchMode, 2
IfWinExist, Bloco de notas
{
WinActivate ; use the window found above
}
else
{
WinRestore, ahk_exe calc.exe
WinActivate, ahk_exe calc.exe
}
I'm on Win7, but the above worked for me.
Here is an example of a good and complete implementation of a function that tries to activate a window.
Semicolons introduce comments in AHK. There has to be a white space before it, otherwise it's seen as part of the string (alias winactivate "Calculator;")
so, use
WinActivate, Calculator ;
or just omit the ;, for it doesn't contribute anything

Sending key strokes to a window

I want to use AutoHotkey to run a program and send some keystrokes.
But I don't get it to work. The program pops up, and then nothing happens.
Here is what I have so far:
run, c:\windows\sysnative\gfxv4_0.exe
WinActivate, "Intel(R) Graphics Control Panel"
SendInput {Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Enter}
Just for testing, I have also tried to send some keys to notepad, but that doesn't work either. The notepad window pops up, but then nothing:
run notepad.exe
WinActivate "Unbenannt - Editor"
SendInput abc{Tab}{Tab}xyz
I have also tried WinActivate without parameters, but no results either. Have also tried with Send, SendPlay, SendEvent and SendRaw. No change.
System is Windows 8.1 64 Bit, latest Service Packs.
Core i7, 8 GB, 2 screens.
Remove the quotes
The parameters of AHK commands are literal strings unless specified otherwise in the help for a command or you explicitly make the parameter an expression: WinActivate, % "some string"
Wait for the window to appear before activating it because launching an application takes time:
WinWait Intel(R) Graphics Control Panel
Maybe there's ® instead of (R). Use the exact window title text from Window Spy application that comes with AutoHotkey.

Resources