How can I select the specific window I want from a list of CMD windows with the same name with AutoHotKey? - autohotkey

I want to make a AutoHotKey script that will send command to a certain CMD window, but I am having problems with selecting the needed window, because I am running at least 3-4 CMD windows and their titles all start with "C:\Window\System32\cmd.exe" so at most I just looping trough the windows one by one.
How can I select !the specific window I want from a list of CMD windows with the same name ?
Most of the cases those are the CMDs I use and I want to target the first one (Upper left corner) which has the most generic name.

You could try starting it from AHK and retrive the ID automatically from there ...
You also could try to build a function which "teaches" which CMD to use ... this would require to click in them CMD window once after it appeared ... basically your AHK script then have to read the UID of this window.
WinGet
Retrieves the specified window's unique ID, process ID, process name, or a list of its controls. It can also retrieve a list of all windows matching the specified criteria.
WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
e.g.: WinGet, OutputVar , ID , A would retrieve the ahk_id of the active window
But without further details it is hard to tell what you really need.

I dont think you can distinguish different cmd.exe windows with AutoHotkey.
But you can use other command line software which will allow to distinguish different command line sessions with AutoHotkey. For example, here and here are some other command line software. Other software are easily findable with google. Look at there screenshots, most of them have tabs for different command line sessions. You can switch between different tabs by using AutoHotkey GUI automation commands.

when initializing the windows you could use the title command.
Run, %comspec% /k cd c:\ && title MyWindow 1 && tasklist
winwait,MyWindow 1
WinMove,MyWindow 1,,20,20
Run, %comspec% /k cd c:\ && title MyWindow 2
winwait,MyWindow 2
WinMove,MyWindow 2,,20,365
ControlSend,,taskkill /pid ` ,MyWindow 2

Related

Disable Ctrl key simulation by Win Key in AHK

I've got two AHK scripts running simultaneously.
First is:
#I::Run calc.exe
And second:
^I::Run notepad.exe
So, when I press Win + I to run first script, second script starting too, because WIN key simulates CTRL key. How to disable it? Without change keys.
Assuming that you are trying to open calculator with the first script and Notepad with the second, you forgot to put the Run command before calc.exe in the first script.
In other words, the reason that it appears that the first script does not function is not caused in any way by the second script, just change the code of the calculator script to:
#I::Run calc.exe

How do I find the number of windows of a certain program that are open in AutoHotKey?

I am new to AHK and would like to find the number of windows of a certain program open at any time and store that in a variable.
I have a script that opens an Opera window when I press the caps lock key, but I would only like three of these windows open at any one time, so when there are more than three Opera windows open and I press the caps lock key it does nothing.
I would also like the caps lock button never to capitalise text (in other words, to have caps lock state always off)
How do I do this?
You can use WinGet with the Count operation (see docs) to get the number of windows matching a certain filter.
You need to find the right filter of course. You can use the Window Spy utility for that which comes with AutoHotkey.
In this case I already did it: You'll see that the window class (ahk_class) of the Opera windows is Chrome_WidgetWin_1. However, this would be true for Chrome, Chromium, etc. as well, so we further have to filter for the program EXE filename (ahk_exe) of opera.exe. (The reason we don't just filter by ahk_exe is that we don't want to include things like an "there are updates available" box or whatever other non-main window Opera may have open, I guess.)
The final result is:
WinGet cnt, Count, ahk_exe opera.exe ahk_class Chrome_WidgetWin_1
MsgBox There are %cnt% Opera windows open

How achieve a two line Prompt?

In the batch language of Microsoft's CMD.EXE console window, I never liked having my command start at the far right, after a long display of the directory path. So in my Control Panel → System → Advanced System Settings → Environment Variables I saved the following assignment, where $_ is like a Soft Return:
PROMPT=[$P\]$_$+$G$S
The displayed prompt was two lines like this:
[C:\Temp\]
>
(The $+ tracks pushd and popd, the fancier than chdir commands. $S is space. By the way, the ^ character a line wrap/continuation character in batch, just as backtick ` is in PowerShell.)
Now I want the same-ish two line prompt in PowerShell. There is good news and bad news.
The good news is I can achieve that in my open PowerShell window by typing at the > prompt:
function prompt {'[' + $(get-location) + '\] SHIFTENTER > '
(By SHIFTENTER I mean press Shift+Enter, what I think might be called a "soft return"?)
....... BAD NEWS, PROBLEM ......
I want to put the above function prompt ... line into my profile PowerShell script, namely Microsoft.PowerShell_profile.ps1 (at path $Profile). But how?
Notepad.exe has no support for Shift+Enter.
MS Word understands Shift+Enter, but when I SaveAs .txt, and then examine with Notepad++, I see a plain CR-LF (meaning \r\n, 0x0d 0x0a).
Notepad++ menu Edit → Character Panel enables me to insert special ASCII characters into my .txt / .ps1 file, such as 0x0b called VT (for "vertical tab"). But despite some claims on websites, VT is not behaving like a Soft Return when I use it in my function prompt ... profile .ps1 file (I also run the profile .ps1 script to retest).
Can the prompt I want be established by a profile .ps1 script?
The PowerShell equivalent of your batch-prompt is:
function prompt { "[$(Get-Location)\]`r`n$("+"*(Get-Location -Stack).Count)>" }
#`r`n is just a shorter way of writing [System.Environment]::NewLine
Add it to the profile to suits your needs:
AllUsersAllHosts:
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersPowerShell:
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
AllUsersISE:
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
CurrentUserAllHosts:
C:\Users\username\Documents\WindowsPowerShell\profile.ps1
CurrentUserPowerShell:
C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
CurrentUserISE:
C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

powershell console : any way to recall a command from keyboard shortcut?

I know I can use F7 to display command history and I can search the history to find a command that I've typed before ( like for example :)
Get-History |select -expand commandline |sls proc
but I wonder if the is a way to use a keybord shortcut to cycle through the history (like ctrl+R does on linux console) ?
Tab completion supports searching through memory, you could type:
#proc<TAB>
to cycle through commands that match the string 'proc'. But if you're looking for a more bash like editing experience, then you want PSReadline - https://github.com/lzybkr/PSReadLine.

Mouse Move application add command line arguments to auto start when windows starts

I have the application
http://movemouse.codeplex.com/
and I want to launch the app at startup (which I can do) but I also want to automatically hit the "Start" button so it turns on as soon as windows starts.
I need to have command line options to do this.
Anyone know of a command line option to do this? And/or a command line list of options available for this program?
Thank You
From looking at the settings, there are three options, that have to be set:
Automatically start Move Mouse on LAUNCH (same as press start when Move Mouse is opened)
Automatically launch Move Mouse at Windows LogOn
Minimize on start
I assume that the options work as presented.
Otherwise, as said before writing your own MouseMover in AutoHotKey is easy. and compiling it to an exe is easy too.
Here is some AutoHotKey code:
#Persistent
#SingleInstance force
SetTimer MoveMyMouse, 60000 ; 1000 ms = 1 sec.
Return
MoveMyMouse:
MouseMove, 1, 0, 1, R ;Move the mouse one pixel to the right
MouseMove, -1, 0, 1, R ;Move the mouse back one pixel
Return
^!#Pause::ExitApp
Load the code in AutoHotKey and test it, once your'e happy compile to your own MouseMove.exe
What is does:
During startup it starts a timer that executes the little sub-routine labeled MoveMyMouse every 60 seconds. This little sub-routine will move your mouse one pixel back and forth.
I also added an escape by pressing Ctrl+Alt+Win+Pause.
create a cmd file that starts your app and sends a key press to either the left or right "Windows" keys
triggering the windows key will open the start menu
to trigger the windows key, you need to download nircmd.zip and unzip its folder somewhere, then cd the path to that folder
paths may be case sensitive
start "C:\path-to-your-apps\app-name.exe"
cd "C:\path-to-nircmd-folder\"
nircmd sendkey lwin press
do not run your app on startup
instead run the cmd file on startup
to run the cmd file on startup, you first need to make a desktop shortcut to it.
do not right click cmd file > create shortcut
right click the cmd file > send to > desktop (create shortcut)
a window should appear
place the following into the browse field
C:\Windows\System32\cmd.exe /C "C:\path-to-cmd-folder\cmd-name.cmd"
name the shortcut then press the enter key
next, right click your new desktop shortcut > properties
navigate to shortcut tab
set "Run" to "Minimized" so you don't see the command prompt pop up as it runs your cmd file
finally, copy or move your shortcut into your startup folder
"C:\Windows\User\your-user-name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"