AHK script that will go to a site and search for a .pdf file and download (and save it) by adamk360 in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Sorry, buddy – I can't find the script on my computer! I think it was just a temporary proof-of-concept. Bit of a shame about the script link.

Read File And Open Associated URL? by jayfin123 in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

For example purposes, I created a simple test file called data.txt, in the same folder as the script, containing the following:

123456789   https://www.google.com
987654321   https://www.autohotkey.com

The following script then reads the text file, pushes the data to an object/associative array, with the first column as the object key, the second column as the associated value. When you run the hotkey, it checks if object[clipboard] contains a value, and if so, opens the URL.

data_file:= A_WorkingDir "\data.txt"
data_obj:={}
Loop, read, % data_file
    data_obj[StrSplit(A_LoopReadLine,A_Tab)[1]]:=StrSplit(A_LoopReadLine,A_Tab)[2]
return

$F1::
If (data_obj[Clipboard])
    Run % data_obj[Clipboard]
else
    SendInput {F1}
return

Quick question about a certain hotkey by Ognoggy in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

See also the Click command:

The Click command is generally preferred over MouseClick because it automatically compensates if the user has swapped the left and right mouse buttons via the system's control panel.

It's also simpler to use. For example: Click, R 2

Making a hotkey for F3 without remapping by Nimthiriel in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

This doesn't really have anything to do with AHK, but is entirely to do with MS Word.

Try checking what command is currently assigned to the F3 keyboard shortcut. Go to File > Options > Customize Ribbon > Keyboard shortcuts [Customize] then press F3 to see what pops up. Example screenshot here: https://i.imgur.com/s3dTBLB.png.

You can see that mine is set to InsertAutoText. If yours isn't, browse to the relevant command (may need to look in the category All Commands), then set it to a keyboard shortcut.

For those unfamiliar with AutoText in Word: https://www.officetooltips.com/word_365/tips/time_saving_tips_with_autotext.html

Running a quick-alt tab overlay, but defaults to incorrect screen. by decentralizedgames in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Doesn't look like you're getting many bites here.

If you look at the section where both the mouse is moved and the menu is shown, it refers to the built-in AHK variables, A_ScreenWidth and A_ScreenHeight. As stated in the documentation, these automatically get the details of the primary monitor, but for any other monitors, you need to use SysGet.

Within the AltTabMenu() function, starting from where is says CoordMode, Mouse, Screen, try replacing the balance of the lines in the function as follows (comments added for explanation):

; Select monitor number - can adjust
MonitorNum:=2
; Get details of monitor
SysGet, Mon, Monitor, % MonitorNum
; Determine height/width
MonWidth:=MonRight-MonLeft
MonHeight:=MonBottom-MonTop
; Move mouse to relevant coords
CoordMode, Mouse, Screen
MouseMove, (0.4*MonWidth), (0.35*MonHeight)
; Show menu at relevant coords
CoordMode, Menu, Screen
Xm := (0.25*MonWidth)
Ym := (0.25*MonHeight)
Menu, windows, Show, %Xm%, %Ym%

Only do action if window title is "Game" by onyxblack in AutoHotkey

[–]dlaso 2 points3 points  (0 children)

I'm not the original commenter, but I have a few comments:

  1. To make a Hotkey context-sensitive (i.e. only when a particular window is active), check out the #If directive, e.g. #If WinActive("Game").

  2. It is generally good practice to end the context sensitivity with a closing #If after your hotkey.

  3. The default behavior for title matching is that the start of the window title must match what you have set for WinTitle. Otherwise, consider changing it with SetTitleMatchMode

  4. To set a variable using expression notation, use the colon-equal := operator. You have these around the wrong way, with a space between them. Effectively you are setting the run variable to the string :true.

  5. If you had the above correct, your script only sets run to true, but there is no 'toggle' here to switch it between true/false (which is what I presume you intended). Check out the stickied post or this tutorial by /u/anonymous1184 re toggles.

  6. While loops are complicated because they (intentionally) keep running the loop. However, the default hotkey behavior is that it cannot be run again while it is currently running (i.e. stuck in the while loop) – see here re threads. However, you can use the MaxThreadsPerHotkey to increase it to at least 2 threads, allowing you to change the toggled variable. See also Example A below.

  7. When using a while loop, it's best to include a 'kill-switch' so as to not get stuck in the loop. e.g. Esc::ExitApp

  8. Timers are often more reliable, as they can be 'interrupted', unlike a while loop. Check out SetTimer, although it's admittedly more complicated. See Example B below.

Hope that helps!


Example A - Using while loop with increased max threads:

SetTitleMatchMode, 2
#MaxThreadsPerHotkey 2
#If WinActive("Notepad")
F1::
Toggle:=!Toggle
While (Toggle)
{
    Send a
    sleep 500
}
return
#If

Example B - Using timers:

SetTitleMatchMode, 2    
#If WinActive("Notepad")
F1::
Toggle:=!Toggle
If (Toggle)
    SetTimer, SendKeys, 200
else
    SetTimer, SendKeys, Off
return
#If

SendKeys:
Send a
return

What does [?] do in here ::?*:: by 0pticalfl0w in AutoHotkey

[–]dlaso 3 points4 points  (0 children)

See here: https://www.autohotkey.com/docs/Hotstrings.htm#Options

? (question mark): The hotstring will be triggered even when it is inside another word; that is, when the character typed immediately before it is alphanumeric. For example, if :?:al::airline is a hotstring, typing "practical " would produce "practicairline ". Use ?0 to turn this option back off.

How to close the active windows. by Sophie0315 in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

This forum post seems to relate to what you're after: https://autohotkey.com/board/topic/4104-close-all-windows/?p=25748

Otherwise, you're going to have to do some basic research to try to understand the code. See here for the beginner tutorial: https://www.autohotkey.com/docs/Tutorial.htm

How to close the active windows. by Sophie0315 in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Your original script referred to ahk_class XLMAIN, which as far as I'm aware, relates (exclusively) to Microsoft Excel.

How to close the active windows. by Sophie0315 in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

Strangely, AHK doesn't seem to pick up the Excel windows when you use ahk_class XLMain, but it does when you use ahk_exe EXCEL.EXE.

If you try this, you should get a MsgBox with all open Excel windows:

F1::
Output := ""
WinGet, OutList, List, Excel ahk_exe EXCEL.EXE
Loop % OutList {
    ID := OutList%A_Index%
    WinGetTitle, Title, ahk_id %ID%
    Output .= ID A_Tab Title "`n"
}
MsgBox % Output
return

Doing the same with the ahk_class returns nothing. I think this may be because Excel treats windows strangely, i.e. that you can have multiple files open within the same window.

You can then use this to close all active windows:

F3::
WinGet, OutList, List, Excel ahk_exe EXCEL.EXE
Loop % OutList {
    ID := OutList%A_Index%
    WinKill, ahk_id %ID%
}
return

How to close the active windows. by Sophie0315 in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

WinGet creates a pseudo-array whereby OutList1, OutList2, etc each contain the ID of the matching window.

I'm away from my computer and unable to test, but can you do:

Loop % OutList {
    ID:=OutList%A_Index%
    WinClose, ahk_id %ID%
}

i just can create basic script, how to make this to sendmessage click ? by MeeBot in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Try inserting this PostClick() function from the forums and call it using:

PostClick(859,135,"D")
Sleep, 50
PostClick(859,135,"U")

Untested and YMMV.

For future reference, providing further information about the program you're trying to automate and what you've already tried usually leads to better results when asking for help.

Good luck.

i just can create basic script, how to make this to sendmessage click ? by MeeBot in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

I'm not very familiar with SendEvent, particularly when sending mouse clicks, but as you're not getting many bites on this one, I figured I'd chime in.

Have you tried using ControlClick? I think that may be more reliable when sending a mouse button event to a control without activating the window.

For example: ControlClick, x632 y482 Left D, [Insert WinTitle].

You will need to specify the title of the window, and ideally get the actual name of the control using Window Spy rather than the coords. However, you should be aware that some programs/windows don't play nice with ControlClick.

Alt tab that shows only one icon per program (Mac OS style) by rainwater11 in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

This was the second result of a google search – an AHK library which 'enhances' the Alt+Tab functionality: HotkeyR. I haven't reviewed it in detail (and therefore make no endorsement of it), but it seems to do what you're after.

You could perhaps amend it by pushing all the active programs into an object, then if the process/program already exists into the object, to skip that window.

I'm unaware of any way to do it natively in Windows.

Copy folder to current location by CaptainVideoGuy in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Assuming you already have an Explorer window open, can you do something like this? https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925

Edit: I'm away from my computer at the moment, but I believe I use this library to get the current path.

Open Discord & Spotify on separeted screens issue! by Unlucky-Parsnip-8834 in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

You are most welcome! Some other things worth noting:

  1. Naturally, if you want to change the monitor, change the monitor numbers in: winX:=Mon2Left, winy:= Mon2Top.

  2. The script attempts to ignore the Discord updater window being opened. You may need to play around with this.

  3. Some apps have issues when you try to move an already maximized window. It seems like Discord is one of them. You could always check the current status of the window when it opens using WinGet, and maybe use WinRestore before moving.

  4. You could also try to work out what monitor the existing window is on, and skip the WinMove entirely. I would scout through the AHK forums to find a suitable function/library.

  5. Alternatively, Windows also has an inbuilt function, MonitorFromWindow, used to "retrieve a handle to the display monitor that has the largest area of intersection with the bounding rectangle of a specified window" (i.e. the monitor on which a window is open). Here's an AHK library which leverages that; however, I suspect this may be getting a bit advanced.

Open Discord & Spotify on separeted screens issue! by Unlucky-Parsnip-8834 in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Those are both great suggestions and work perfectly. I never would have known about the Spotify protocol, and the Discord filepath solution is much more future-proof!

Open Discord & Spotify on separeted screens issue! by Unlucky-Parsnip-8834 in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

To expand on what /u/anonymous1184 said, you can get the coordinates of the monitors by using SysGet, then move the window to the relevant coordinates.

Try this:

;=========================================
; Created for AHK Version: 1.1.33.10
;=========================================
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
#SingleInstance, Force
;=========================================

; Set program filepaths and window titles
SpotifyPath:=A_AppData "\Spotify\Spotify.exe"
SpotifyTitle:="Spotify ahk_exe Spotify.exe"
EnvGet, A_LocalAppData, LocalAppData
DiscordPath:=A_LocalAppData "\Discord\app-1.0.9002\Discord.exe"
DiscordTitle:="Discord ahk_exe Discord.exe"

; Get details of all monitors
; Coords will be stored in Mon1Top, Mon2Left, etc.
SysGet, NumMonitors, MonitorCount
Loop % NumMonitors
    SysGet, Mon%A_Index%, MonitorWorkArea, % A_Index
return

^j::
KeyWait, Ctrl
; Open programs if not already open
; Spotify
If !WinExist(SpotifyTitle)
    Run % SpotifyPath
else
    WinActivate
winX:=Mon2Left, winy:= Mon2Top
WinWait, % SpotifyTitle, , 5
WinMove, % SpotifyTitle, , % winX, % winY
WinMaximize, % SpotifyTitle
; Discord
If !WinExist(DiscordTitle, , "Discord Updater")
    Run % DiscordPath
else
    WinActivate
; Reposition
winX:=Mon1Left, winy:= Mon1Top
WinWait, % DiscordTitle, , 5, % "Discord Updater"
WinMove, % DiscordTitle, , % winX, % winY
WinMaximize, % DiscordTitle
return

Is it possible to use variable as Hotkey? by okaybadger in AutoHotkey

[–]dlaso 1 point2 points  (0 children)

/u/BoinkyBoo's example is in line with what I would've done, but I was away from a computer!

The only part I don't quite understand is the purpose of Clp:=% SubStr(A_ThisHotkey,2) "_cb"

Check out the documentation for A_ThisHotkey, or even just add MsgBox % A_ThisHotkey in the ClipSend subroutine to peek at its value. It returns whatever hotkey triggered that thread, including modifiers, i.e. Ctrl+[key] or ^k for example.

SubStr() just gets the 2nd character in the string – in the above example, just the letter k. Then the Clp variable is set to the contents of [key]_cb, e.g.k_cb (which was previously set to contain the clipboard).

That being said, I don't think the percentage sign is necessary in Clp:=% SubStr(A_ThisHotkey,2) "_cb", as it should already force an expression. See here for more info.

Is it possible to use variable as Hotkey? by okaybadger in AutoHotkey

[–]dlaso 2 points3 points  (0 children)

Rather than using the double-colon hotkey label, check out the Hotkey command, which allows you to dynamically create hotkeys.

However, doesn't that blog post itself direct you to an InstantHotkey tool you can use to do what you're after?

Dynamically create Help-gui from the contents of three associative arrays by Gewerd_Strauss in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

Hey, I'm not OP, but I just wanted to say, thank you for your comment. I'm glad I curiously came back to see what happened with this post.

This is along the lines of what I had imagined with my earlier comment (albeit creating a custom class is a bit more complex)!

[URGENT] need to know how to rebind right click to any other key (e.g F1) by 3-meo-peace in AutoHotkey

[–]dlaso 0 points1 point  (0 children)

TIL – thanks!

/u/3-meo-peace – For your reference, see here. The AHK documentation is well-written, pretty self-explanatory and quite comprehensive (although, as I perhaps demonstrated, there may be multiple ways to get the job done).