Can anyone pls explain this ahk script logics/commands - autohotkey

Can anyone pls tell what is the purpose of two sequential commas and then 1 in the below given ahk script?
Pause:: Suspend
Pause,,1
return

If the script is suspended you can't unpause with that very same button because the hotkey is disabled.
In that case you need to use the OperateOnUnderlyingThread in the Pause command parameters:
Pause,,1 makes a single button (in this case the button Pause or Break) work as both pause and unpause. It allows the Pause command to run a second time (i.e. to unpause).
Pause::
Suspend ; disables or enables all or selected hotkeys and hotstrings.
Pause,,1
return

It indicates that the first parameter is blank.
https://lexikos.github.io/v1/docs/Language.htm#commands
The comma separating the command name from its parameters is optional, except in the following cases:
When it's necessary to prevent the line from being interpreted as a legacy assignment or assignment expression.
MsgBox, := This would be an assignment without the comma.
When the first parameter is blank.
MsgBox,, Second, Third

From https://www.autohotkey.com/docs/commands/Pause.htm :
Pause [, OnOffToggle, OperateOnUnderlyingThread]
OnOffToggle
If blank or omitted, it defaults to Toggle. [...]
Pause,,1 is the same as Pause,Toggle,1

I think I got the answer.
Two commas mean there is a blank value, which in ahk means 'Off'. In other words it'd be perhaps same if it were: Pause, Off, 1
And 1 means on. That means, it is equal to
Pause, Off, On
I'm only 95% sure of the above.

Related

notepad++ How to assign two macro to same key?

Using the GUI: I assigned a macro to allow me to select the current line my cursor is on. I assigned it to 'ctrl+a', and reassigned 'select all' to 'ctrl+alt+a'. I now want, when I press 'ctrl+a' a second time, to have it highlight the remainder of the paragraph. Currently these commands are available via the following key-press:
Instruction:
1. Home->shift+end --highlights one line
2. Home->shift+end->shift+end -- highlights connected lines
So 1. is assigned to 'ctrl+a', but I'm stuck at this point. How do I assign ctrl+a when hit a second time to highlight the connected lines/paragraph? Details/specifics in layman's terms would be appreciated. Again, I've only been using the gui options, I'm not familiar with the more codey options. Note that it doesn't allow me to use
ctrl+a->shift+end.
I'm not overly familiar with macro and hotkey binding, so I'm unaware if this is a limitation or if there's a workaround, other than writing a program to fix it.
Not a coder, but from what I know of Lua I cameup with:
is_press=false
if btn(ctrl+a) and !is_press then btn(Home->shift+end) is_press=true end
if btn(ctrl+a) and is_press then btn(Home->shift+end->shift+end) is_press=false end
I could assign 2. to ctrl+shift+a, as a separate macro if all else fails.
Short answer, I don't think this is possible with a singe shortcut/macro.
Behind the scenes, Scintilla is doing the selecting. Once you've done the selection, going back to "home" the second time will reset the word wrap extension.

Remove the space in the end of text

I'm just starting to learn to use Autohotkey, mostly for text expansion, ie when I type goo and it will become www.google.com. Problem is, in Windows, it always leaves a space in the end and that's annoying. What can I do to avoid that?
I tried added {bs} and {left 1} to the script but it moves the cursor before the last character eg www.google.com
The reason there is a space at the end is because you're pressing space to end your hotstring. If you use the O option, it will omit the ending character. Try this:
:O:goo::www.google.com
More information can be found here in the official help docs: https://www.autohotkey.com/docs/Hotstrings.htm
Found the answer myself! My original code syntax was like this...
::goo ::www.google.com
Doing so leaves a space in the end
I changed it to...
::goo ::
Send, www.google.com
return
Another option is to use :*:goo::www.google.com
The asterisk means that the hotstring will be activated without waiting for you to end the hotstring (though in this case, typing 'good' would pose a problem)

How to manually trigger Autohotkey hotstrings?

In my main Autohotkey script I have several hundred hotstrings like these:
::fe::for example
::f::and
::fi::for instance
::fo::fortunate
::foy::fortunately
::glo::global
::gloy::globally
::ha::have
::hv::however
Fairly often it would be convenient to trigger a hotstring manually (e.g. by pressing ALT-9) rather than pressing and end character. Is there a way to do this? I haven't found anything in my Googling, so maybe there isn't. But it would be useful.
I've read the hotstrings options e.g. :*: but this isn't the same - I want normal hotstring operation, but also the option to manually force them to trigger as needed.
Updated:
So what you are in fact looking for is using ALT+9 as an end character. I'm not sure but you can probably not use key-combinations for that (see hotstring doc). I cannot think of a really clever way of doing that right now. You might try something like
::fe::
Transform, CtrlC, Chr, 3 ; comes from ahk input documentation, I never really understood how this is supposed to work but I guess there is a code for alt 9 as well somehow
input, key, L1 I M ; wait for the next 1 key
if(key==CtrlC)
sendraw forExample
return
Old answer:
You have to outsource the hotstring body:
::fe::gosub forExample
forExample:
send for example
return
, then you can define a hotkey somewhere:
!9::gosub forExample
If you want to be cool, use functions instead of subroutines.
Note:
::fe::something
is just a short form for
::fe::
send something
return
::fe::for example
::f::and
::fi::for instance
::fo::fortunate
::foy::fortunately
::glo::global
::gloy::globally
::ha::have
::hv::however
!8:: trigger_hotstring("fi")
!9:: trigger_hotstring("ha")
trigger_hotstring(hotstring){
Loop, Read, %A_ScriptFullPath%
{
If InStr(A_LoopReadLine, "::"hotstring "::")
{
SendInput, % StrSplit(A_LoopReadLine,"::"hotstring "::").2
break
}
}
}
If you use AutoHotkey v1.1.06+ you can use #InputLevel
::fe::for example
::f::and
; and so on
#InputLevel, 1 ; sending space will trigger hotstrings above this line
!F9::Send {space}
Edit:
I now see you want to omit the end char which needs a bit of extra work
One way would be to duplicate the hotstrings with additional options:
::fe::for example
:*O:fe_::for example ; duplicate the hotstrings like so
::f::and
::fi::for instance
::fo::fortunate
; and so on
#InputLevel, 1
!9::Send _
Another way would be to remove the endchar
::fe::for example
::f::and
::fi::for instance
::fo::fortunate
; and so on
#InputLevel, 1
!9::
Send {space}
Sleep 100 ; give it time to expand the hotstring, experiment with timing
Send {bs} ; now remove trailing space
Return
I generally use TAB as a trigger for all my hotstrings. like
:*:#pm ::mail1#protonmail.com
:*:#G ::mail2#gmail.com
:*:Btw ::By the way,{Left}
Note that the space that you see here is a tab and not a space. you can do this instead of doing Alt+9 to trigger your macro hotstring.
you can even use more than one Tab so you can be sure that you only trigger it when you really intend to.

Autohotkey Input Times Out Because MatchList Isn't Matched

Here's my AHK script
:*:if ::
SendInput IF{Space}
Input cond, I V T5,, then
msgbox %ErrorLevel%
msgbox %cond%
if (ErrorLevel = "Match")
{
SendInput {Enter}End If{Space}'%cond%
}
Return
When I type If x = 1 then I get an ErrorLevel of 'Timeout' and a cond of 'x = 1 then'
My understanding is that when I type then it's supposed to stop the Input and set the ErrorLevel to Match.
I've tried putting it in quotes, using single letters in the MatchList, and including and end key, but none of works. The few examples I could find of using MathList look just like mine.
Input cond, I V T5 *,,% " then"
Without the asterisk option, an item in MatchList needs to be the next thing typed. So If Then would match then in the MatchList. But If anything then doesn't match then in the MatchList because it's trying to match anything then, not just then.
With the asterisk option, if anything then is matched because the next thing typed after If contained then. That causes problems if you type if heathen then because the then in heathen triggers it. The space before then should fix that, but it doesn't.
AHK help says that the MatchList respects spaces, but it doesn't seem to do that when the space is before the first (or only) item in MatchList. The two ways around that are to include a dummy word at the beginning or to use the % thingy to quote the MathList item and include the space.
See also http://ahkscript.org/boards/viewtopic.php?f=5&t=3979
I strongly recommend using RegEx powered hotstrings for this purpose:
#Include <Hotstrings>
hotstrings("if (.*?) then", "If %$1% then``nEnd If%A_SPACE%")
The definition of "T" in the AutoHotkey Help File states this:
T: Timeout (e.g. T3). The number of seconds to wait before terminating the
Input and setting ErrorLevel to the word Timeout. If the Input times out,
OutputVar will be set to whatever text the user had time to enter.
Basically, this is saying exactly what is to be expected (and what is actually happening) with your script. So, for me when I type "if x = 1 then" my "if" is immediately replaced with the caps lock IF and a space.
After 5 seconds, the first MsgBox appears with "Timeout" as the text (again, expected since ErrorLevel is set to the word "Timeout" when the "T" option is present). Once that MsgBox is dismissed, I receive the second MsgBox which (according to the help file) contains OutputVar which is what I (the user) had time to enter in before the Timeout.

What does # (hash) mean when it doesn't mean Windows key?

Not sure where to search or how to define the keywords. What is the difference between the following?
#IfWinActive, Some Window Title
IfWinActive, Some Window Title
What is the # doing there? I know that in shortcuts, # stands for Windows key, but surely this has to mean something else.
I had been trying to make up a script and the If-else blocks did not work at all. Finally I figured out that it's because I added the # symbol. But I don't find any documentation regarding this kind of use of the # symbol.
The hash is a totally different command. If you search the index in the autohotkey documentation, you will find an entry for both IfWinActive and #IfWinActive.
[The hash...] Creates context-sensitive hotkeys and hotstrings. Such hotkeys perform
a different action (or none at all) depending on the type of window
that is active or exists.
The #IfWin directives are positional: they affect all hotkeys and
hotstrings physically beneath them in the script. They are also
mutually exclusive; that is, only the most recent one will be in effect.
The # only represents the windows key when you use it as a hotkey assignment designation. In AutoHotkey, any time you see a # at the beginning of a command it has something to do with AutoHotkey directives.
Conclusion:
If you just want regular if-else statemens and don't need to affect the context of hotkeys, then don't use the #.