I have successfully used to following autohotkey script to achieve what I want (remove title bar and window frame from a windowed game):
;-Caption
LWIN & LButton::
WinSet, Style, -0xC00000, A
return
;
;+Caption
LWIN & RButton::
WinSet, Style, +0xC00000, A
return
;
What I want is for "WinSet, Style, -0xC00000, A" to be executed automatically when a specific application is launched.
Any feedback would be greatly appreciated!
Altough wOxxOm's answer is perfectly acceptable. You can also do this in a persistent script by using Settimer and WinExist .
#persistent
SetTimer, isItRunning, 1000
isItRunning:
if winexist("yourprogram")
WinSet, Style, -0xC00000
Return
Simply make an AHK launcher for the game and use it instead of the shortcut icon or taskbar icon or whatever else you're using to launch the game.
Run, d:\somepath\game.exe
WinWait Game window title goes here
WinSet, Style, -0xC00000
ExitApp
Related
I have this script to run a online game, click trough the startup screens and input my password for me.
Ever since the latest patch however, the %MWOStartupTime% has become rather unpredictable and this doesn't work reliably anymore. I'm suspecting the game is firing some early web requests. Or something.
So here's the question: Instead of waiting for a fixed time, can I somehow test if a given window not only exists but is responsive? That way I could loop, wait for a responsive window and start "clicking" then.
I'm also happy about alternative ideas/solutions. If it turns out I need to use the WinAPI I can rewrite it in a real programming language too.
Run, MWOClient.exe, %MWODirectory%
; Wait for the Client to launch
WinWait, MechWarrior Online,, 20
WinActivate, MechWarrior Online
; Wait until the window is responsive
Sleep, %MWOStartupTime%
; Press Escape a few times to skip the loading screens
Loop %MWOScreenLoops% {
WinActivate, MechWarrior Online
Sleep, %MWOScreenTime%
SendInput {Esc}
}
; Click the password textbox
WinActivate, MechWarrior Online
Click %MWOPasswordBoxXCoord%, %MWOPasswordBoxYCoord%
Sleep 500
; Type the password
WinActivate, MechWarrior Online
SendInput %MWOPassword%
Sleep 500
; Copy the password to the clipboard in case the
; password input fails
clipboard = %MWOPassword%
; Click login
Click %MWOPlayButtonXCoord%, %MWOPlayButtonYCoord%
Have you tried following WinActivate with WinWaitActive? You should be able to drop the Sleep command.
WinActivate, MechWarrior Online
WinWaitActive, MechWarrior Online
https://www.autohotkey.com/docs/commands/WinWaitActive.htm
I have the AutoHotKey EnterPad Keyboard/Pad with 120 Programmable Keys
It works by sending a Hotkey press for each key to an AutoHotKey script which has a Label function for each key named 001 through 120
Below is my AHK Label function called when key 115 is pressed.
My code allows me to select rows in any Windows Listview component and it will show a popup GUI window with a textbox filled in with the data from the selected rows with each column separated with a TAB space. I can then copy or save it or view it whatever I like.
;---------------------------------------------------------------------115-----
; Copy Selected Windows Listview Items to Tab Spaced Text - Show popup Window Gui
; https://superuser.com/questions/814831/copy-to-clipboard-from-table-list-in-a-program-on-windows
115:
Gui, SelectedListRowsTextGui:Destroy
MouseGetPos, , , , ListView_hwnd, 2 ;2 means return HWND
ControlGet, selected_row_text, List, Selected, , ahk_id %ListView_hwnd%
Gui, SelectedListRowsTextGui: +ToolWindow +AlwaysOnTop -Caption
Gui, SelectedListRowsTextGui:Add, Edit, vUnused_variable x11 y15 w950 h66, %selected_row_text%
Gui, SelectedListRowsTextGui:Add, Button, x62 y84 w140 h30 +Center, Close
Gui, SelectedListRowsTextGui:Show, ,
return
ButtonClose:
Gui, SelectedListRowsTextGui:Destroy
return
Return
Problem
My issue is that once the popup window is opened from my AHK GUI, my CloseButton label dose not get called when I click the close button.
I realize it likely has something to do with it being nested under the key 115s label function. How can I best achieve the desired result?
I tried moving the CloseButton label outside of the 115 label however it still is not called from the GUI's Close button click.
You can see I have named the GUI SelectedListRowsTextGui this is to allow this Enterpad.ahk script to contain many GUI windows for different actions it will perform.
Preview of the GUI window this script creates when listview items are selected and this Label function is called:
I got it now....
Since my GUI is named SelectedListRowsTextGui I had to add that name in front of my CloseButton label name so it is now SelectedListRowsTextGuiButtonClose and works great
How to use Autohotkey to automatically close, minimize, maximize or send keys to a window as soon as it pops up? I can detect a dialog and close it with this:
WinWaitActive, TITLE
WinClose, TITLE
But this doesn't work if the window isn't open on script execution.
This is a very common task AHK is used for.
First you need the title of the window you want to address. Read How to get the title of a window with AHK?.
The code
For the basic functionalitiy of closing a window we need Loop, WinWaitActive and WinClose.
Example for a Firefox window with Stack Overflow open.
Loop {
WinWaitActive, Stack Overflow - Mozilla Firefox
WinClose,
}
Explanation
The Loop repeats the process to close the window multiple times. WinWaitActive waits until the the window gets activated (pops up) and WinClose closes it.
Hint: If you don't specify a specifiy window title like with WindowClose the last found window, which is the one from WinWaitActive is used.
minimize/maximize
Instead of WinClose use WinMaximize or WinMinimize to perform the corresponding action.
Sending Keys
If you want to send specific keys (e.g. Enter) to the window use Send
Loop {
WinWaitActive, Stack Overflow - Mozilla Firefox
send {Enter}
}
Additions
If the basic version does not work or you want to create an more advanced script, here are some possible modifications.
More Force
If WinClose does not work try WinKill or Send, !{F4} to use more force.
As Admin
Admin rights might be necessary to close the window, use this code snippet on top of your script to make sure it runs with full access.
If not A_IsAdmin ;force the script to run as admin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
Other matching methods
On default the window title has to be an exact match. To change this behavior and allow partial or start with matches use SetTitleMatchMode on top of your script, e.g. SetTitlematchMode, 2 for partial match.
Instead of title, the window class (ahk_class) or .exe (ahk_exe) from Window Spy can be used.
WinWaitActive, ahk_class MozillaWindowClass
or
WinWaitActive, ahk_exe firefox.exe
Select the one which suits your needs carefully to only react to the correct window.
I am trying to obtain the Seamless windows effect with TightVNC Viewer.
Basically I set the client visible area to an application with
"C:\Program Files\TightVNC\tvnserver.exe" -controlapp -shareapp <app PID>
then I use the following AutoHotkey script to hack TightVNC Viewer window (where I hide the toolbar):
^!h::
IfWinExist, antonio - TightVNC Viewer
{
WinSet, Style, ^0xC00000 ; title bar, without you can move only with win-key
WinSet, Style, ^0x800000 ; thin-line border
WinSet, Style, ^0x400000 ; dialog frame
WinSet, Style, ^0x40000 ; sizing border, without you cannot resize
WinSet, Style, ^0x200000 ; vertical scroll bar
WinSet, Style, ^0x100000 ; horizont scroll bar
}
return
; http://www.autohotkey.com/docs/misc/Styles.htm
The script toogles the border and other window elements.
I am still working with the styles, but the main problem is that scrollbars don't go away.
How can I get rid of them?
Side note
An interesting side effect of sharing windows in VNC locally, that is with the loopback connection, is that you can obtain kinda of X Server in Windows, appealing for multi-monitors systems.
I found a "semi-general" solution for scrollbars. They are not a property of the window, but of some edit child control. Getting the control name via Window Spy, you can remove the bars from some app, with:
Control, Style, -0x100000, <control name>, <app window name>
Control, Style, -0x200000, <control name>, <app window name>
For example it works for for Notepad, where <control name> is Edit1.
Unfortunately TightVNC uses a non standard Window class, TvnWindowClass1, and I am unable to affect its scrollbars.
Anyway, replacing the server option -shareapp <app PID> with -sharewindow <app window name>, there are no-scrollbars.
The following is a local working sample assuming you want to share calc.exe, whose window name is Calculator.
Press Ctrl+Alt+h once and you will locally start a client-server VNC sharing the Calculator window. Press again and you get the seamless effect. Press again and you get back to standard view (and you can move, size again).
If toggling window style with Ctrl+Alt+h, TightVNC toolbar doesn't toggle too, set it on or off manually in normal view from the window control menu or with
Shift+Ctrl+Alt+t.
If you want to use the script in two distinct systems, you have to split it in two parts where server commands are run on the server side and client ones on the client system.
Note that, for a more general use, regexp are used in naming the target application window.
Note
The script is useful as is to duplicate a window. Window mirroring is something trivial in Linux X Window (for the server nature of the display), which instead require tools paid money in Windows. Mirroring turns useful when you have a multi-monitor system or a projector and you want to duplicate, not the whole desktop, but only some particular windows on the second monitor (projector).
^!h::
SetTitleMatchMode RegEx
IfWinExist, TightVNC Viewer$
{
WinGet, Style, Style
if(Style & 0x800000) {
WinGetPos, X, Y
Sleep, 6000
WinSet, Style, -0xC00000 ; title bar, without you can move only with win-key
WinSet, Style, -0x800000 ; thin-line border
WinSet, Style, -0x400000 ; dialog frame
WinSet, Style, -0x40000 ; sizing border, without you can't resize
Send !+^t ; no toolbar
WinMinimize
Sleep, 500
WinRestore
WinMove, X, Y
} else {
WinSet, Style, +0xC00000 ; title bar, without you can move only with win-key
WinSet, Style, +0x800000 ; thin-line border
WinSet, Style, +0x400000 ; dialog frame
WinSet, Style, +0x40000 ; sizing border, without you can't resize
Send !+^t ; no toolbar
}
}
IfWinNotExist, TightVNC Viewer$
{
Run, calc
Run, "C:\Program Files\TightVNC\tvnserver.exe" -run
Sleep, 1000
Run, "C:\Program Files\TightVNC\tvnserver.exe" -controlapp -sharewindow Calculator
Run, "C:\Program Files\TightVNC\tvnviewer" 127.0.0.1
}
return
I want to capture the key event "right mouse button pressed, then left mouse button pressed". No problem in autohotkey. However I am having trouble with still allowing the right-mouse key to work alone.
1) this works:
RButton & LButton::
Send X
Return
works as expected:
If I press right mouse button, then left mouse button, "X" is sent to the active window
right-click event is captured by Authotkey: no context menu appears when I press the right mouse button alone. This is the intended outcome
2) this works
~RButton & LButton::
Send Y
Return
works as expected:
If I press right mouse button, then left mouse button, "Y" is sent to the active window
right-click event is not captured by Authotkey: context menu does appear when I press the right mouse button alone or together with the left button. This is the intended outcome
3) Now I want to do different things depending on the active window.
this does not work (careful: this will disable righ-click in every application)
#If WinActive("ahk_class MozillaWindowClass")
RButton & LButton::
Send X
Return
#If !WinActive("ahk_class MozillaWindowClass")
~RButton & LButton::
Send Y
Return
does not work as expected:
in Firefox left-right sends X, in other applications left-right sends Y
however, right-click is disabled in every application
What am I doing wrong here?
edit:
the goal is this: I want a global hotkey on Right+left-click with RButton & LButton . In specific applications that I have tested for compatibility, I want right+left click to suppress sending right-click, and then send right-click manually using autohotkey. However, since some applications might have trouble processing mouseevents sent by autohotkey, in all untested applications I want to use ~RButton & LButton with the ~ to pass throught right-click events
Here's one that supports right click dragging!
Hotkey, LButton, off
#IfWinActive ahk_class MozillaWindowClass
RButton & LButton::
Send X
Return
RButton::return
#IfWinNotActive ahk_class MozillaWindowClass
~$RButton::
Hotkey, LButton, on
while GetKeyState("RButton", "P") {
continue
}
Hotkey, LButton, off
Return
LButton::Send Y
Return
It handles RButton manually. When RButton is pressed, it enables the LButton hotkey and waits for RButton to be released before deactivating it. The RButton hotkey uses ~, which passes the click through normally.
LButton is disabled at the start by the line at the top.
Another way would have been to send {RButton Down} at the start of the hotkey and {RButton Up} at the end.
In response to your edit, the only programs that reject Autohotkey's sent events should be those that rely on low level hooks... The real trouble with the method down at the bottom is it only sends a single click, not processing holding the button. This method, and sending down and up separately, should both do that properly.
The bug with active window described at the bottom of this answer still exists, but that's a problem with the #IfWin[Not]Active.
Old stuff
See the documentation on the ampersand (emphasis mine):
You can define a custom combination of two keys (except joystick buttons) by using " & " between them. In the below example, you would hold down Numpad0 then press the second key to trigger the hotkey:
Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad
In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:
Numpad0::WinMaximize A ; Maximize the active/foreground window.
Numpad0::Send {Numpad0} ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
The presence of one of the above hotkeys causes the release of Numpad0 to perform the indicated action, but only if you did not press any other keys while Numpad0 was being held down.
So, following that example:
#If WinActive("ahk_class MozillaWindowClass")
RButton & LButton::
Send X
Return
RButton::return
#If !WinActive("ahk_class MozillaWindowClass")
RButton & LButton::
Send Y
Return
RButton::Send {RButton}
Note RButton requires a variant that does nothing in WinActive, at least with my testing (see below): RButton::return
Since I'm using Autohotkey standard, not Autohotkey_L, I don't have #If and the above was untested. The following I did test, and it works.
#IfWinActive ahk_class MozillaWindowClass
RButton & LButton::
Send X
Return
RButton::return
#IfWinNotActive ahk_class MozillaWindowClass
RButton & LButton::
Send Y
Return
RButton::Send {RButton}
An interesting bug I've noticed is the second (NotActive) variant applies occasionally to Firefox:
Another window is active
RButton down is sent
Firefox is not active, so the second variant is processed
<delay> (RButton is held down, though the delay could be imperceptible, in the order of milliseconds, to infinite)
Firefox becomes active
<delay> (still held down)
RButton up is sent, which sends RButton as per the documentation. Because Firefox became active in the delay between the active window check and when RButton is sent, RButton is sent to Firefox.
This happens when both Firefox and another window are visible, and the other window is the active one at the time of the click.
I've tried to fix this bug by adding an extra IfWinNotActive check within the RButton hotkey, but it did not seem to work.