I'd like to download GTA V for PC. The download is extremely slow (40kb/s), but when you click pause and then start it again downloads with 5,5mb/s for 1 minute.
I want to write a script for it in AutoIt.
But how i can focus the window AND work on in the foreground.
The window info of the download manager (mouse pointed at the button)
http://i.imgur.com/ckBudsO.png
My script looks like this at the moment:
While 1
; Here, the focus has to go, right?
MouseClick ( "primary" [, 637, 460 [, clicks = 1 [, speed = 0]]] )
Sleep(1000)
MouseClick ( "primary" [, 637, 460 [, clicks = 1 [, speed = 0]]] )
Sleep(60000)
WEnd
Ensure that you got right coords from Autoit Window Info screenshot
Try to use WinActivate() and ControlClick() (in that choice the mouse is not used) :
Opt("MouseCoordMode",2)
While 1
$hwnd = WinActivate('Launcher')
MouseClick ( "primary",637 ,460) ; with mouse coords
Sleep(1000)
ControlClick ( $hwnd, "", "[CLASS:AfxWnd110su; INSTANCE:2]") ;... and without mouse
Sleep(60000)
WinSetState ( $hwnd, "", #SW_MINIMIZE ); Minimaze the Launcher
WEnd
Related
I made a simple timer using Autohotkey with the help of some snippets from the Autohotkey forum,
Like the page loading bar on many of the web pages in browser, but for Windows.
Now it work as expected, with those features:
Stay on top of the Screen
Take up very little Screen Space (4px height only)
Clik Through and Tranasparent (won't stop me from mouse over top right corner to close a window)
Simple enough, just change the .ahk code to config color, time, size etc.
But, I notice while transparency been set to 100, there alway be a gray transparent background,
Gray backound of progress bar
Some one know any parameter I can tweak to make the progress bar without background ?
Full Autohotkey code here for this simple timer:
#Persistent
WinTitle = toptimer
Gui,New,hwndMyGui
global MyProgress
; 30 minutes
time := 30 * 60 * 1000
tick:=A_TickCount+time
Gui, +E0x20 -Caption +AlwaysOnTop +Owner +LastFound
; Gui, -Caption +AlwaysOnTop +Owner +LastFound
WinSet, Transparent, 100
; Gui,Margin,0,0
Gui,Margin,-1,-1
Gui,Add,Progress,w1920 h4 cbFF0000 Range%A_TickCount%-%tick% vMyProgress
; Gui,Show,NA
Gui, Show, x0 y0 w%A_ScreenWidth%
While A_TickCount<=tick {
GuiControl,,MyProgress,% A_TickCount
Sleep 16
}
Gui,Destroy
ExitApp
Thanks #0x464e for nice suggestion,
Now I just draw a single color gui and change it's width
#Persistent
Gui,New,hwndMyGui
time := 1 * 60 * 1000
tick:=A_TickCount+time
Gui, +E0x20 -Caption +AlwaysOnTop +Owner +LastFound
WinSet, Transparent, 100
Gui, Color, FF0000
While A_TickCount<=tick {
width0 := A_ScreenWidth * (1 - (tick - A_TickCount)/time)
Gui, Show, x0 y0 w%width0% h5
Sleep 16
}
Gui,Destroy
ExitApp
That made the code even simpler, and the background is gone.
But while this timer is running, the left mouse button is not function right, clicking on explorer's top right Minimize/Restore/Close is not work.
But the Minimize/Restore/Close button of vscode is working fine.
After quit the timer, everything just work fine.
Some one help to figure out why that happens.
The problem occurs because your Gui, Show command activates the the window each time.
Add the NA(docs) option to get rid of this.
Alternatively, you could use e.g WinMove(docs) to resize the window.
In that case you'll also need to use SetWinDelay(docs) to remove the delay that happens after a WinMove command.
I'm not sure which approach is better, I can't be asked to open up the AHK source to see what exactly is the difference between these two. If you care enough (and understand C/C++ well enough) be sure to take a look.
Here are the revised scripts for both approaches:
time := 1 * 60 * 1000
tick := A_TickCount + time
Gui, +E0x20 -Caption +AlwaysOnTop +Owner +LastFound
WinSet, Transparent, 100
Gui, Color, FF0000
While (A_TickCount <= tick)
{
width0 := A_ScreenWidth * (1 - (tick - A_TickCount) / time)
Gui, Show, x0 y0 w%width0% h5 NA
Sleep, 16
}
ExitApp
SetWinDelay, 0
time := 1 * 60 * 1000
tick := A_TickCount + time
Gui, +E0x20 -Caption +AlwaysOnTop +Owner +LastFound
WinSet, Transparent, 100
Gui, Color, FF0000
Gui, Show, y0 x0 h5
While (A_TickCount <= tick)
{
width0 := A_ScreenWidth * (1 - (tick - A_TickCount) / time)
WinMove, , , , , % width0
Sleep, 16
}
ExitApp
At work I have a 3 monitor setup. I would like to move the current application to a second or a third monitor with a key binding. How to do that?
I use the following script to cycle the focused window through the screens.
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, 'n', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
The screen library helps finding the right "display". allScreens lists the displays in the same order as they are defined by the system. The hs.window:moveToScreen function moves to a given screen, where it's possible to set the UUID.
The following code works for me.
Hitting CTRL+ALT+CMD+ 3 moves the currently focused window to display 3, same as if you would choose "Display 3" in the Dock's Option menu.
function moveWindowToDisplay(d)
return function()
local displays = hs.screen.allScreens()
local win = hs.window.focusedWindow()
win:moveToScreen(displays[d], false, true)
end
end
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "1", moveWindowToDisplay(1))
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "2", moveWindowToDisplay(2))
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "3", moveWindowToDisplay(3))
I've answered this in Reddit post here, but in case anyone comes across this question here's the answer:
The Hammerspoon API doesn't provide an explicit function for doing this, so you gotta roll out with a custom implementation to achieve this:
-- Get the focused window, its window frame dimensions, its screen frame dimensions,
-- and the next screen's frame dimensions.
local focusedWindow = hs.window.focusedWindow()
local focusedScreenFrame = focusedWindow:screen():frame()
local nextScreenFrame = focusedWindow:screen():next():frame()
local windowFrame = focusedWindow:frame()
-- Calculate the coordinates of the window frame in the next screen and retain aspect ratio
windowFrame.x = ((((windowFrame.x - focusedScreenFrame.x) / focusedScreenFrame.w) * nextScreenFrame.w) + nextScreenFrame.x)
windowFrame.y = ((((windowFrame.y - focusedScreenFrame.y) / focusedScreenFrame.h) * nextScreenFrame.h) + nextScreenFrame.y)
windowFrame.h = ((windowFrame.h / focusedScreenFrame.h) * nextScreenFrame.h)
windowFrame.w = ((windowFrame.w / focusedScreenFrame.w) * nextScreenFrame.w)
-- Set the focused window's new frame dimensions
focusedWindow:setFrame(windowFrame)
Wrapping the snippet above in a function and binding it to a hotkey should cycle the currently focused application across your different monitors.
Not exactly the answer to OP but leaving this here for others who also want to cycle through monitors and maximize on each screen:
local app = hs.window.focusedWindow()
app:moveToScreen(app:screen():next())
app:maximize()
You can put this in a function and bind it to Ctrl + Alt + n like so:
function moveToNextScreen()
local app = hs.window.focusedWindow()
app:moveToScreen(app:screen():next())
app:maximize()
end
hs.hotkey.bind({"ctrl", "alt"}, "n", moveToNextScreen)
I'd like to start two Terminals and put them at specific positions on my screen. I know how to do this with one Terminal but what do I have to do to open a second Terminal and position it next to the first one?
Here is the code for one Terminal:
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "2", function()
hs.application.launchOrFocus("Terminal")
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = 960
f.h = 540
win:setFrame(f)
end)
So this potentially gets quite complex, but what I would do is have the hotkey check to see if Terminal is already running. If not, launch it and put it in position 1. If it is already running, focus it, activate the menu item to open a new window, and put it in position 2.
I have a script for entering records in our system that was originally working fine with a MsgBox, but I added a GUI to show the record entry. Now the script stops after the first record.
In the example below I've stripped out all of the actions and record lines to help make this easier to parse, but I've kept in all the important stuff and tested this version of the script.
Loop, read, C:\_AutoHotKey\AA_test.txt
{
StringSplit, LineArray, A_LoopReadLine, %A_Tab%
aaduedate := LineArray1
aauniqueid := LineArray2
aaprefix := LineArray3
aasequence := LineArray4
aadescript := LineArray5
aaelig := LineArray6
;-------------------------------------------------------------------------------------
;Use these to test the file match in the Input File.
;Remove surrounding comments and surround the rest of the script up to the last brace.
SendInput, Prefix: %aaprefix% {enter}
SendInput, Sequence: %aasequence% {enter}
SendInput, Description: %aadescript% {enter}
SendInput, Eligibility: %aaelig% {enter}
SendInput, ID Card: %aaidcard% {enter}
;---------------------------------------------------------------------------------------
;Pop-up validation menu
Gui, Add, Button, x22 y380 w100 h30 , &Submit
Gui, Add, Button, x362 y380 w100 h30 , &Cancel
Gui, Font, S14 CDefault, Verdana
Gui, Add, Text, x152 y10 w210 h30 +Center, Is the entry correct?
Gui, Font, S10 CDefault, Verdana
Gui, Add, Text, x102 y40 w90 h20 , %aaprefix%
Gui, Add, Text, x102 y70 w130 h20 , %aaelig%
Gui, Add, Text, x312 y70 w30 h20 , %aadescript%
Gui, Add, Text, x432 y70 w30 h20 , %aaidcard%
Gui, Font, S8 CDefault, Verdana
Gui, Add, Text, x132 y380 w230 h40 +Center, Click Submit/press S to continue. Click cancel to stop script.
; Generated using SmartGUI Creator 4.0
Gui, Show, x9 y250 h428 w480, Auto Action Validation
Return
ButtonCancel:
ExitApp
ButtonSubmit:
Gui, Submit ;
MouseMove, 630,55
Sleep, 100
SendInput, {Click 630,55}
SendInput ^S
Return
}
The buttons do work and clicking Submit will send the MouseMove and SendInput. But after that it just stops and doesn't load the next record in the text file.
Thanks in advance!
You have a return command within the loop.
This exits the program
See this example.
This loop should run 5 times, but the return
command stops it after the first run.
Loop, 5
{
msgbox, %A_Index%
return
}
I was able to get this to work by removing the submit button from the GUI and moving it to a MsgBox.
The GUI is basically the same but the Submit and Cancel lines have been removed along with the returns and all logic following it.
Next, a MsgBox was added to confirm the data. This now uses the GUI to display the contents of the record and the MsgBox to confirm and move on to the next record.
Also, there's some code I stole (and don't really understand) that moves the MsgBox so that it doesn't block the data entry screen in the receiving app.
Here's the new code that replaces everything after Gui, Show, x9...
OnMessage(0x44, "WM_COMMNOTIFY")
MsgBox 4, AA Entry, Would you like to continue? (press Yes or No)
WM_COMMNOTIFY(wParam) {
if (wParam = 1027) { ; AHK_DIALOG
Process, Exist
DetectHiddenWindows, On
if WinExist("ahk_class #32770 ahk_pid " . ErrorLevel) {
WinGetPos,,, w
WinMove, 90, 650
}
}
}
;If the user responds yes, then close the Gui (Destroy) and enter the record
IfMsgBox Yes
{
Gui destroy
Sleep, 100
}
else
ExitApp
}
Thanks, and I hope this is helpful to someone.
Hello just wondering is their any possibility for a batch file to have a user entry specified time? Lets say for example i want to enter a time of 26 minutes, after that the batch file will be like a countdown timer when it reaches 0 it does 1 mouse click to an icon on the desktop? or where to pointer of the mouse was pointed?
Try Autohotkey or AutoIT, it's very easy to do these thing with this... or you could just get an autoclicker...
Example
#Persistent
Pause
SetTimer, MouseClicklabel , 1560000 ; 1000 = 1 second, meaning 1560000 = 26 Minutes
Pause::Pause
MouseClicklabel:
Click
Return
The toggle key is Pause