Run this. It shows you how <code>Break</code> completely stops the current loop and how <code>Continue</code>stops the current iteration of a loop and proceeds to the next.
MsgBox Starting a loop Loop, 5 { if (A_Index = 1){ MsgBox Index equals 1. Breaking out of loop Break } MsgBox You'll never see this msgbox. Ever. }
MsgBox, Done with first loop.`nStarting second loop.
Loop, 5 { if (A_Index = 1){ MsgBox Index equals 1. Continuing to next iteration of the loop. Continue } MsgBox Index is currently at %A_Index%. }
MsgBox, Done with second loop.
ExitApp
It may be possible, but not easy to do by any means. just_me provides code examples and libraries for using RichEdit (the thing that powers WordPad included with Windows) from AutoHotkey in this post: https://autohotkey.com/boards/viewtopic.php?f=6&t=681
Personally I've built a code editor with RichEdit, rather than a text editor, in AHK and it's been a long process of a lot of work. https://github.com/G33kDude/CodeQuickTester
> I'm trying to make a script, purely to see if it can be done
Yes. This can be done. Now you don't have to make it to see if it can be made.
This sub strongly frowns upon trolling, spamming, and pvp cheating scripts.
If you want to know how to do this, here's a link to the AHK <code>Tutorial</code>. Start reading until you're proficient enough to create it.
That being said, I'd like to give you a word of warning about pranking people with computers.
There will ALWAYS be someone smarter than you when it comes to this stuff. My ex-coworker paid dearly to learn this lesson when he met me (to be honest, the guy was a sub-par tech and had no business working in a NOC).
After I caught him playing "jokes" on another tech, I explicitly warned him not to ever touch my system. Low and behold, he screwed with my computer 1 time when I was gone. Took me like 10 minutes to unfuck it up.
For the next year, his computer would blast the entire song "It's Raining Men" (the guy was a homophobe, hence the song choice) at full volume when he logged in and he couldn't figure out why or how I did it, nor could he figure out how to fix it himself. Even using Google-Fu.
He started turning his speakers off when the computer booted up...to which I just modified things so it'd wait 30 min to a couple hours to play the song. He ended up just disabling his speakers completely.
I hope you take something from that.
AHK is not compiled, just interpreted.
So, that's normal for most of the scripting languages. And as the name implies a script should not need security, if security is required maybe switching to a real programming language.
I mean not going nuts with the machine code but at least something that ensures bytecode as not been tampered (think of the JVM).
On the other side of spectrum, obfuscation will stop any curious/prying eyes, no need for more. Why? Any programmer that can reconstruct obfuscated code can create it from scratch and will not waste time cracking his head with something that tedious when the coding is fairly easy.
With other forms of protection you can simply attach a debugger, decompile, find the entry points for routines, etc, idk any kind of reverse engineering.
The main point is: scripts are good as plain text, if you need to protect IP there's legal ways to do so and the last option should be forms of source code encryption because in the end all the routines of the binaries load into memory and from there you can get whatever you want.
<^<+d:: FormatTime, date,, MMddyy Send, %date% return
https://autohotkey.com/docs/Hotkeys.htm#Symbols > ^ Control > > + Shift > > < Use the left key of the pair.
https://autohotkey.com/docs/commands/FormatTime.htm#Date_Formats_case_sensitive
> MM Month with leading zero (01 – 12)
> dd Day of the month with leading zero (01 – 31)
> yy Year without century, with leading zero (00 - 99)
Mind the case sensitive part.
read the "read this before posting" topic and/or basic autohotkey documentation/tutorial
Use <code>MouseGetPos</code> to get the position of the mouse first.
Then run your commands.
Then use <code>MouseMove</code> to put the cursor back where it was.
I take thanks in the form of paypal, venmo, or credit card numbers.
​
But yeah, you should really look at the Quickstart or the tutorial. Yeah.
You can use the Raw or Text send method or use <code>SendRaw</code>.
#IfWinActive, ahk_exe SciTE.exe ::sd::Send, {Raw}%A_ScriptDir% ;::sd::Send, {Text}%A_ScriptDir% #If
Alternately, you can escape the characters.
#IfWinActive, ahk_exe SciTE.exe
:*:sd::Send, %A_ScriptDir
%
#If
https://autohotkey.com/boards/viewtopic.php?t=39218
msdn just uses friendly names, since it would be pointless to know the thousands of message handlers in the os by number. you wouldn't normally be referencing them directly in a proper IDE, where they are defined as constants in the relevant libs
Great time to learn about objects/arrays.
Make an array for your numbers.
numA := [1,2,3,4,5,6,7,8,9,0]
Then make an array for your letters.
letterA := ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
Now you can use <code>Random</code> to generate a random number between 1 and 10 for the number and 1 and 26 for the letter.
Use the generated numbers as your index for the arrays.
numA := [1,2,3,4,5,6,7,8,9,0] letterA := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
F1:: Random, num, 1, 10 Random, let, 1, 26 MsgBox, % numA[num] " " letterA[let] return
If you want performance, use sendinput. (This is all covered in the Send docs.
If you need large amounts of text to be sent, putting the text on clipboard and pasting by sending ^v
will dump the text faster than anything (but this doesn't work for some games and apps).
But the issues you're describing sound like poor coding problems.
Your script's timing should never be able to be thrown off by the act of sending text.
Unfortunately, your code can't be checked b/c you didn't post any.
From the look of it, yes there is. Check out this thread. https://autohotkey.com/board/topic/7022-acbattery-status/
You should be able to get battery stats then use basic math to perform a function when it reaches 25% or below then have the script constantly checking it with a SetTimer until then.
Check the documentation. It's very good.
Hotkeys is the one of the main specific sections that you would probably want.
Make sure you read those links that blackened posted. They more than cover what you're asking. (Also, be sure to check out the <code>AHK Beginner Tutorial</code>)
What your asking for is as simple as this:
:*:\d::^<
I believe you can use ControlClick.
To illustrate:
^5::
run, calc WinWaitActive, Calculator ControlClick, Button14, Calculator ControlClick, Button23, Calculator ControlClick, Button10, Calculator
return
Once you press Ctrl+5 , the script will launch Calculator and then click buttons "9" "+" "5" , even if you are moving the mouse during this time.
Think of it as "invert the value". If it was any number other than 0, set it to zero, if it was 0 set it to 1.
errorlevel is a special variable. It's one of many special variables in AutoHotKey which are automatically created that serve specific functions. In this case whenever a command is executed in autohotkey it will place a value into errorlevel to describe if the command encountered any problems.
if !errorlevel means "if no problems were encountered"
You can find out more by looking at the autohotkey documentation.
> You should be able to use the built-in A_Username in any version v1.1.28+
> Edit: Source is the last post in this thread: https://autohotkey.com/boards/viewtopic.php?t=15926#p209769
I'm not sure how you're wanting me to respond to this.
I already covered that built-in variables are the only variables that can be used.
A_UserName
is a built-in variable, right?
Why link to a page where Lexikos is just confirming what's already in the docs?
Jethrow's Guide To COMs (This is the guide I used to learn COMs)
That should get you started. If you hit a snag, make a post about it along with your code. There are power users on here that are very familiar with Excel Objects and will be able to show you what's going wrong.
aka [abstraction](https://en.wikipedia.org/wiki/Abstraction_(computer_science\)), the foundation of all modern programming languages and the article I always link to when the topic comes up. many similar scripting and interpreted platforms are cited here, curious none of them are labeled as "real" or "fake"...
it's a common misconception to perceive them in order of difficulty, where these platforms are more a hierarchy of purpose. reducing work is a common goal for higher level langs, but using them to their full extent is not any easier for the most part than anything compiled in assembly, since they rely on so many of the same concepts for any kind of proficiency, and also completely different skill sets in whatever use case they were designed for.
even autohotkey functions could be written in ASM if you wanted, though I don't see many practical reasons to, when you could just run libs optimised for those purposes.
any newcomers with the proper fundamentals, and motivation to appreciate platforms outside their own area of expertise could spend a matter of minutes thumbing through the docs, and immediately find access to most of the same tools they have been using in whatever "real" language they are coming from.
are they the same tools, of course not, else what would be the point of writing a new language?
FYI I wrote TapHoldManager not so long ago that will handle any number of taps, with an optional hold (Long press) at the end.
eg tap/tap/tap or tap/tap/hold
Array/Object Method:
ChatHistory := [] ; Let's create an Array.
If (ChatHistory[ChatHistory.MaxIndex()] != tofromguild2) then ; If the Last Person is not tofromguild2 { Found := False Loop, % ChatHistory.MaxIndex() - 1 ; Since we concluded the last person is not who you were seeking, we'll remove them from the Loop. { If (ChatHistory[A_Index] = tofromguild2) then ; If we find them in the Array, we'll remove them from the Array. { ChatHistory.RemoveAt(A_Index) Found := True Break } } If !Found && (ChatHistory.MaxIndex() = 10) then ; Hmm... If we didn't find them in the Array and the list already contains 10 people, we'll remove the 10th person from the Array. Feel free to modify "(ChatHistory.MaxIndex() = 10)" if you want a smaller or larger Array. { ChatHistory.RemoveAt(1) } ChatHistory.Push(tofromguild2) ; Let's add tofromguild2 to the Array. }
; Let's list the 10 most recent people you chatted with.
; Most recent is ChatHistory[ChatHistory.MaxIndex()]
; Second most recent is ChatHistory[ChatHistory.MaxIndex() - 1]
; Third most recent is ChatHistory[ChatHistory.MaxIndex() - 2] ... You get the idea.
Loop, % ChatHistory.MaxIndex()
{
theList .= ChatHistory[ChatHistory.MaxIndex() + 1 - A_Index] "n"
}
MsgBox, % "Reverse-chronological Order:
n" theList
This is exactly why we need to see the code.
Your problem is because you've programmed your hotkey to not fire when shift is being held.
F1::
means "when F1 is pressed and ONLY when F1 is pressed". Shift+F1 will not fire it.
There are these things called <code>Hotkey Modifier Symbols</code>. They're like options for your hotkeys. Look at the wildcard modifier *
and add it to your hotkeys. They'll fire whenever you press the key, regardless if another key is being held.
; Essentialy i want my SHIFT+ARROW UP key to act as Numpad 8 ; + is shift. Up is Up Arrow. +Up::Numpad8
This is covered under <code>Hotkeys (Mouse, Joystick, and Keyboard Shortcuts)</code> and <code>Remapping (Keys or Mouse Buttons)</code>.
Use Scite4AutoHotkey, it has a built-in debugger, which you cannot do with VS Code and AHK as far as I know.
Even better, use the DebugVars modded version of Scite
> MouseMove, 576, 839 > > click, 576 839 > > MouseMove, 1544, 841 > > click 841 > > sleep 6000
Click has a number of overloads. You will see click with a single numerical value is to indicate the number of clicks
You just need to change this bit
Random, rand, 1, % afk1.MaxIndex() Random, rand, 1, % afk2.MaxIndex() Send % afk1[rand] afk2[rand]
to:
Random, rand1, 1, % afk1.MaxIndex() Random, rand2, 1, % afk2.MaxIndex() Send % afk1[rand1] afk2[rand2]
as because you were using 'rand' as the variable for both line numbers, it was using the same line number for both text documents.
I would also get the script to fire on a hotkey and replace 'ExitApp' with 'return' - but I'm not sure if you don't know that already.
Close the script?
The hotkey won't function if the script isn't running.
I think what you may be wanting to do is use Ctrl+F as a hotkey in a specific program. If so, look up <code>#IfWinActive</code>. That will let your ctrl+f work normally when that program isn't going.
Example of how to do this is covered in the "Read This Before Posting!" stickied tutorial post.
Use the <code>Random</code> command.
Try this:
MinRN := 1 MaxRN := 10 Loop { If( A_TimeIdle < 100 ){ Random, RN, %MinRN%, %MaxRN% ToolTip % RN } Sleep 100 }
> Will this GUI even work in fullscreen games
No. At a minimum, you'd need to run windowed mode to have a custom gui display.
> Where should i start to make this work?
Start by making a simple <code>Gui</code> so you understand how to make one. This part's easy.
Then you'll have to start playing with formatting to make it look like you want.
You'll most likely have to play with transparency overlays and other stuff to make it work.
Is it doable? Yes.
Is it easy? Hell no. This will be a project for you.
Should you consider doing it another way? I would!
I'd just use your numpad or F keys to macro the commands you want. Any keys you don't normally use.
F1::Send, Need help!
Numpad7::Send, I'm dead! Send backup!
The good news is that if you don't want to use hotkeys like that, some people have worked on radial menus in the past.
See if this helps:
https://autohotkey.com/boards/viewtopic.php?f=6&t=12078
Have you tried Google? This should do what you want.
$c:: KeyWait, c If A_TimeSinceThisHotkey > 500 Send a Else Send b Return
Toggle script is fine. The problem is your h::i
.
You can't put a hotkey in the middle of an else statement. You'd have to create the hotkey somewhere and then use the <code>Hotkey Command</code> to turn it on off
Alternately, you can make an <code>#If</code> directive. This is an easy way to have hotkeys/hotstrings work during certain conditions.
In the script below, F1 toggles the variable toggle
. The directive #If (toggle = 1)
says "whenever toggle equals 1, make this hotkey active". So F1 is able to turn your hotkeys on and off.
toggle := 0 return
F1::toggle := !toggle
#If (toggle = 1) h::i #If
This is covered in the "Read This Before Posting!" stickied tutorial post under:
7) Making Certain Things Only Work in Specified Programs (WindowSpy!)
Code provided from that post:
; Everything following #IfWinActive will only work for the program specified. #IfWinActive, ahk_exe chrome.exe
; Opens a new tab and searches for "autohotkey tutorial" F1:: Send, ^t Sleep, 100 Send, autohotkey tutorial{enter} return
; The second #IfWinActive is to indicate anything past this ; point will work in any program. #IfWinActive
If you want to toggle a bunch of hotkeys on/off, then use a variable to track them and use the <code>#If</code> command.
Very easy to do.
toggle = 0 ; Declare variable so you know it's set to off return
F1::toggle := !toggle ; This sets toggle to the opposite of toggle. ; 1 becomes 0. 0 becomes 1.
#If (toggle = 1) ; Whenever this evaulates true, the hotkeys/hotstrings below are active. F2::MsgBox, Working! #If
The code looks good and does exactly like OP asked, but just as a heads up, not a single one of those curly braces {
}
in your code is needed.
The only time you ever need curly braces is with functions or with if/else statements, loops, or anything where you a condition is evaluated and more than 1 line of code needs to be executed.
See Block/Blocking (Multiple Lines of Code Inside Braces).
Xbutton1:: toggle:=!toggle if (toggle) sendinput, {Lbutton down} else sendinput, {Lbutton up} return
You're mixing up using #IfWinActive as a directive vs using the IfWinActive command.
This:
#IfWinActive, ahk_exe notepad.exe F1::MsgBox, Notepad! #If
#IfWinActive, ahk_exe calc.exe F1::MsgBox, Calculator! #If
is the same as this:
F1:: IfWinActive, ahk_exe notepad.exe MsgBox, Notepad! IfWinActive ahk_exe calc.exe MsgBox, Calculator! return
> COM is unfamiliar territory to me, so this post is quite helpful.
It's not too bad. If you understand javascript and html, you've got a good head start. If not, it's a good thing to learn.
I'd STRONGLY suggest you bookmark this guide by Jethrow and also take a look at and/or bookmark this guide by Mickers. Both are great references and are how I learned the basics of using IE com.
>It's too bad I have to use IE though.
Why exactly is it so bad?
You don't even have to look at it. Set ie.visible := false
.
All you do is use a settimer to check your element in the background. You don't have to ever actually USE Internet Explorer for your general web surfing needs. Use Chrome/FireFox/Safari/Opera for your normal needs.
You shouldn't hate IE COM, you should be happy it's there because Chrome, FireFox, Opera, Safari, or any other of the browsers don't have a nice interface to use.
And I'm saying this as someone who dislikes IE.
The problem here is you put too much stuff on the same line as the hotkey. It should look like this:
^,:: Send,{ALT DOWN}{TAB}{ALT UP}{tab}{tab}{tab}{tab}{tab}{tab}^v{enter}{enter} Sleep,2500 Send,{ALT DOWN}d{ALT UP}imacros://run/?m=test.iim{enter} return
You should only put stuff after the :: on the same line if that's all you're going to do with the hotkey. If you have something more complicated like this 3 lines of instruction you should start a new line first.
Also there is a better way to bring up firefox. https://autohotkey.com/docs/commands/WinActivate.htm
ahk does have custom/bound function objects, though what I believe you're looking for can be more conveniently done through built in globals, eg. a_thishotkey
or a_thislabel
There are methods like AHKHID that could let you use an entire second keyboard only for hotkeys. But I don't know how to make it work!
If you bought a macro keyboard, F13 through F24 are usually pretty safe bets.
Bentschis MIDI-Out Class works fine:
https://github.com/Ixiko/AHK-libs-and-classes-collection/blob/master/classes/class_midiOut.ahk
Original Post with Example: https://autohotkey.com/board/topic/91046-midi-library-midiout/
How exact does it have to be? like if within 1 minute is fine then:
settimer minute, 60000 return ;^^^auto-execute section above minute: if (a_hour=17) and (a_min=0) send ^!{numpadenter} return
note that if you need to send it specifically to that program and it doesn't already have focus you will either need to switch to that program (via <code>winactivate</code>) before sending or use <code>controlsend</code>
ah I get what you mean, just being dense. you are right the angle is not properly calculated here, we can fix this
plotellipse(x1, y1, a, r1, r2, byref x2, byref y2) { rad := -(a * 0.01745329252) t := r1 * r2 / Sqrt((r1 * Sin(rad))2 + (r2 * Cos(rad))2) x2 := (x1 + cos(rad) * t) y2 := (y1 - sin(rad) * t) }
https://autohotkey.com/board/topic/75685-help-with-ellipse-co-vertices-values/#entry481601
Bear in mind that #if checks are slower than #IfWinActive checks, and could potentially fail.
If you want to check whether one of multiple windows is active, best practice is to make once check against a Window Group
I can't think of a word search function but there is ImageSearch which you could use to find the button and click on it, that is considering it always looks the same.
It's giving the answer in Radians. To convert it multiply by 180 and divide by pi. Trig Functions
Note: To convert a radians value to degrees, multiply it by 180/pi (approximately 57.29578). To convert a degrees value to radians, multiply it by pi/180 (approximately 0.01745329252). The value of pi (approximately 3.141592653589793) is 4 times the arctangent of 1.
Per the docs, a squiggly boi modifier, ~
, will make it so AHK does not block the key function.
~RButton::MsgBox You clicked the right mouse button.
The problem you're having is NewPTO = %PTO%-%TakePTO%
. AHK thinks you're working with strings, not numbers. This is why I advise everyone to use <code>Expressions</code> instead of traditional syntax.
Try this:
newPTO := pto - takePTO
I have a post here explaining traditional vs expression syntax.
It appears to be down right now.
I'm sure they're aware of it.
Until then, here's a copy of 1.1.30.01 that I downloaded a few days ago.
I was going to remind you that the installer comes packaged with the docs, but it appears the AHK Docs Page is still online.
For something like that I don't see an extreme need to generate the hotkeys dynamically; that'd be more for something like customising hotkeys from a .ini
file.
You just need a test within the hotkeys to check if ScrollLock is enabled.
Which can be done with GetKeyState() combined with an #If statement before the hotkeys so they only trigger when ScrollLock is enabled.
EDIT: Presumably something like this:
#If GetKeyState("ScrollLock", "T") ;If ScrollLock is Toggled, hotkeys below are enabled $Space::SoundPlay, *64 ;Play a sound when spacebar is pressed #If ;Reset hotkey context sensitivity
If you want to switch it to working when ScrollLock disabled, add in the !
NOT operator before the GetKeyState:
#If !GetKeyState("ScrollLock", "T") ;If ScrollLock is disabled, hotkeys below are enabled
Have you tried using Google? Change space into the mouse-button of your choice.
Here's a second one, more "professional" but harder to tell what's going on.
Just for reference, the reason is the backtick/accent (`) is the escape character in Autohotkey.
So Autohotkey is just seeing the backtick on your KeyWait line and thinking it's an escape character and to look at the character directly after it, and then finding nothing.
So you need to use it as an escape character, then put it again after (two backticks in a row).
Like so:
KeyWait, `` ; prevent repeated calls
The %A_ThisHotkey%
suggestion is a cleaner way of doing it though, as someone else pointed out.
> I've been looking far and wide and even tried coding it myself.
The documents on <code>Hotkeys (Mouse, Joystick, and Keyboard Shortcuts)</code> covers this.
Also, see <code>Remap (Keys or Mouse Buttons)</code>.
*a::SendInput, {A Down} *a Up::SendInput, {A Up}
This will get you started. You will need the function "ImageSearch". Learn what the parameters are. Then, read the section on ErrorLevel.
​
Most programs should be able to make some choices and decisions. We are going to practice conditional programming now.
This is usually done by a kind of if ... else
statements which may look
like:
IF some_condition THEN do_something ELSE do_other_thing ENDIF
Depending on your programming language syntax could be different and else part is almost always optional. You can read more in wikipedia article on Conditional statements.
Of two numbers, please, select one with minimum value. Here are several pairs of numbers for thorough testing.
Input data will contain number of test-cases in the first line. Following lines will contain a pair of numbers to compare each. For Answer please enter the same amount of minimums separated by space.
example input data:
3 5 3 2 8 100 15
answer:
3 2 15
Test Data:
30 1498170 7120369 2956077 840707 8671830 9707896 -3696593 4087192 -9505627 8690589 -9510475 -864967 -6077300 4347937 -8886623 -1164288 -9103442 -8765944 7304975 -6545893 -5496013 -6173280 4158982 -59199 -1108142 654718 -452456 3161348 -4490970 -1896626 2955382 7007199 -4776257 -4088540 -2152093 -6104426 -4380644 4151313 7982765 -3886271 2841903 8472290 5248761 6764602 2820227 6362138 -4399686 3716784 7596193 -7094710 7170890 -7899820 -3267990 1329873 2040981 5623868 -8015409 -8411475 -1214783 -2506380
Hint: In order to solve this you'll need to read through Variables / Expressions section in the Help Docs. You can copy the data to your clipboard and access it in your script using built in variable Clipboard
.
I use SKAN's list of constants, from his thread here:
https://autohotkey.com/board/topic/18177-crazy-scripting-list-of-win32-constants/
His link has long gone dead so I've reuploaded it here:
https://p.autohotkey.com/static/Constants.W32.ini
Although SKAN does provide a script to parse the ini and present a graphical interface I typically just open it in Notepad++ and run a find command on it to find whatever I'm looking for.
For constants not in this list you can find them online by searching google for C/C++ header files that define them. For example, the first result for "#define SB_BOTTOM" filetype:h
on Google is a file that defines SB_BOTTOM
as 7
.
Edit:
The reason that MSDN doesn't list the values of these constants is because those constants are built-in when you're developing in C/C++ with the appropriate WINAPI development files installed. AutoHotkey doesn't support reading C/C++ header files, so you're stuck looking for and reading them manually (or relying on precompiled lists by other users).
It's covered in the <code>Hotkeys (Mouse, Joystick, and Keyboard Shortcuts)</code> docs.
> A key or key-combination can be disabled for the entire system by having it do nothing. The following example disables the right-side Win key:
> RWin::return
You'd replace RWin
with CapsLock
.
you sure it's being invoked properly, this is an easy mistake if you're working with the both of them through the same console/shortcut. messing that up would send the wrong params, and you have no sanity checks here
autohotkey.exe [switches] myscript.ahk [params]
vs
myscript.exe [switches] [params]
do some error checking and get a proper json lib, I suggest JSON/JXON, I'm using this all the time. maybe overkill here but if you intend to do any more with that, it will save you so much work. then you can objectify your code and not have to build your own strings -
#include a_scriptdir\lib\json.ahk ; in lieu of function variant
if !(a_args.length() = 5) { msgbox not enough params, exiting exitapp }
variables := {id: a_args[2], status: a_args[3], uid: a_args[4], ex_id: a_args[5]}
; prep socket WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") WebRequest.Open("PUT", a_args[1], false) WebRequest.setRequestHeader("Content-Type", "application/json")
; function call from standard lib
str := jxon_dump(variables)
try webrequest.send(str)
catch error
msgbox % error.message "n
n" str
; instantiated class
str := json.dump(variables)
try webrequest.send(str)
catch error
msgbox % error.message "n
n" str
You need colons for your keybinds. I updated your code from legacy to expression.
text1 := "Please return my email message. Thanks" text2 := "If you have any questions please reach out to me" ^1::SendInput, % text1 ^2::SendInput, % text2
Have you considered using hotstrings instead?
AutoHotkey is not a secure langauge, and offers almost 0 protection of data from anyone with a little bit more than average computer skills.
Here's an example of using Win32 Api to encrypt/decrypt: https://autohotkey.com/boards/viewtopic.php?t=5838
To add to this, you can use PixelSearch to determine where to click, if you want to avoid hard coding coordinates (assuming the click target doesn't change visually). Pulover's Macro Creator is quite useful in spitting out an AHK script for PixelSearch.
Requires quotes for :=
Variable1 := "You don't have a pokémon with that number"
Does not require quotes for =
Variable1 = You don't have a pokémon with that number
`t is Tab, not 't.
There are two methods to store strings and numbers as variables: legacy and expression.
The legacy method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs.
The expression method uses the colon-equal operator (:=) to store numbers, quoted strings, and other types of expressions.
> * Chrome can be automated even when running in headless mode
* ^(Launching in headless mode is not currently supported by this library)
you raised my hopes and dashed them quite expertly sir, bravo
So I believe this is an old bug between windows and ahk
This is the code that, mostly, will function as you are asking
( you end up getting another functioning hotkey, but if you never turn numlock off you will never use it)
+Numpad0:: Send, {shift up}={shift down} NumpadIns:: Send, {shift up}={shift down}
Whats going on here is that Shift + Numpad0 in windows is the same thing as NumLock with Numpad0, otherwise known as in NumpadIns in ahk. This is why you are experiencing the normal working behavior of the insert key when using your hotkey. Now by defining NumpadIns as a hotkey (without shift, which would be Shift Insert) your original hotkey can, almost, work correctly. There's another problem. Now that you are technically firing the NumpadIns hotkey while holding down shift, it becomes a + sign. So if we send a {shift up} command before sending = you will get the expected results you wanted.
Edit: changed some wording
Probably. If the prompt comes up as its own window with a unique title, you should be able to use the <code>WinWait</code> methods to detect the popup. From there, accepting the prompt should be straight-forward.
There are other strategies that could be used, too, but without knowing more details hard to say what's most appropriate.
Something like this?
Just have to add a new line to the hotkeyA array and it'll implement it on reload.
<code>BoundFuncs</code> are handy.
#SingleInstance, Force hotkeyA := {"^i":"git{Space}" ,"^b":"echo """" >> .txt{Left 9}" ,"^n":"touch{Space}" ,"^m":"mkdir{Space}"}
for index, value in hotkeyA { bf := Func("SendIt").bind(value) Hotkey, % index, % bf, On } Exit
SendIt(msg){ SendInput, % msg return }
Or did I misunderstand?
Whenever you're timing something, use <code>SetTimer</code>
Loops should be used for things where you know how many times you need to loop through it.
F1:: SetTimer, DoStuff, 10000 return
DoStuff: MsgBox, it's been 10 seconds. return
Quick edit: Also, when you're testing/debugging in AHK, use <code>MsgBox</code>. You can insert it before and after commands, display variables with it to see if things are looking like they're supposed to, and many other things. An invaluable command for troubleshooting.
I'd suggest using <code>FileGetTime</code> to check when the file was last accessed.
Use <code>SetTimer</code> to repeatedly check.
Edit: I don't know of any way to check which specific program last accessed said file. Maybe someone else knows, but I don't think that info is tracked.
> Can Autohotkey move my cursor to a random place on ny screen, with a random interval between 15 and 20 minutes?
> The cursor can’t teleport to a new location, it must actually move.
See the "speed" option of MouseMove.
use devcon for this, probably the easiest way to parse/run code for hardware changes, you don't want an input macro going through the ui
depending on what you intend to do with it a message handler can also be set to manage events on the fly, a hardware device lib can be found here. for example you can have it generate a list of new devices whenever a hardware event is detected, or run code for some particular device
So the easiest way to rebind ctrl + q
would be to just have the Autohotkey script send the existing strikethrough formatting hotkey.
Based on a quick google, it looks like the default hotkey is Ctrl + Hyphen
.
So you want to use the Send command to send that hotkey.
Because we're only doing one thing, there's no need for a multiline hotkey and we can get rid of the return line that ends the hotkey.
So something like this should work:
#IfWinActive, ahk_exe ONENOTE.EXE ;Hotkeys after this will only trigger in OneNote ^q::Send, ^-
I'd suggest using <code>SetTimer</code> instead of looping with sleeps. SetTimer is made exactly for this.
Here's exactly what you typed except I've inserted commands with what you typed out.
; I'm trying to press a button (1) every 30s SetTimer, Press1, 30000 return
; I'm trying to press a button (1) Press1: SendInput, 1 return
; when I press X x:: ; I want it to reset the internal timer SetTimer, Press1, 30000 return
This works exactly as you described. Here's that code added with a b
hotkey toggle:
toggle := 0 return
b:: toggle := !toggle if (toggle = 1) SetTimer, Press1, On else SetTimer, Press1, Off return
Press1: SendInput, 1 return
x::SetTimer, Press1, 30000
I mean I feel like you're just describing a JSON, which most web APIs should return. If you're looking for an AutoHotkey JSON parser I found this post after a quick google search.
For the mouse, those aren't keys but buttons, so you need different codes for that and you need to have the correct mouse driver installed so that your OS even handles these buttons in the first place.
I have a similar mouse but the work PC is locked down. No driver = no buttons!
As for the keyboard mute button, keyboard scan codes are your friend! AHK has a debug window that outputs the scan codes of the keys you press. Here are the details!
I don't have time at the moment to consult furthering the script, but I can spot a few things that might help clean the script up a bit and make some functionality a bit smoother.
At the moment you're doing custom combinations to do most of the hotkeys (e.g. RShift & 5::
), they're generally not recommended for using when you're using a modifier like RShift
as half of the hotkey. For one, they block the use of the first key naturally which is probably why you needed to essentially rebind the shift key at the top.
Instead you can use hotkey modifiers at the start instead of a combo, which would change RShift & 5::
to just this little thing >+5::
The >
indicates the right version of the modifier, and +
is Shift.
That way the shift key isn't natively blocked, and should function normally without having to do the rebinding thing at the start where you made the RShift press RShift (if that's why you did it).
The rest of the modifiers are noted in the Hotkey page of the documentation.
Depending on the programs you're using as well, if you want to use keys without having to use ones that are on your keyboard but are like virtual keys. I've had good success in using the keys F13-24 which are commonly supported, but are rarely natively used.
EDIT:
If you want a huge amount of layouts, you can potentially combine the modifiers.
So you can do something like <!>+5::
Which is left alt (<!
) and right shift (>+
).
ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe
ahk_class Chrome_WidgetWin_1 ahk_exe atom.exe
this is a pretty reliable function I'm using for imgur,
; download to file ; https://autohotkey.com/board/topic/74719-function-remoteresource-for-images-etc/ urltofile(url, file) { static r := false, obj := ComObjCreate("WinHTTP.WinHttpRequest.5.1")
fo := fileOpen(file, "w") if !fo return 0 ; file error
if !r || (obj.Option(1) != url) obj.Open("GET", url) obj.Send()
if (obj.ResponseText = "failed") || (obj.Status != 200) || (comObjType(obj.ResponseStream) != 0xd) return -1 ; server error
iptr := comObjQuery(obj.ResponseStream, "{0000000c-0000-0000-C000-000000000046}") loop { varsetcapacity(buf, 8192) r := dllCall(numGet(numGet(iptr + 0) + 3 * a_ptrsize), ptr, iptr, ptr, &buf, uint, 8192, "ptr*", bytes) fo.rawWrite(&buf, bytes) } until (bytes = 0)
objRelease(iptr) fo.Close() return 1 ; download complete }
whenever requests need to be authorised, token headers should be defined after GET and before SEND. store your hashes in a file to be read in as a static var,
; read client id from file imgur_id() { fo := FileOpen(a_scriptdir "\imgur_client_id", 0) return fo ? fo.read() : 0 }
; query album info imgur_query(album_id) { static client_id := imgur_id() if !client_id return 0
; request json obj obj := ComObjCreate("WinHTTP.WinHttpRequest.5.1") obj.Open("GET", _root album_id) obj.SetRequestHeader("Authorization", "Client-ID " client_id) obj.Send()
; decode response body body := obj.ResponseBody DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata) length := (body.MaxIndex() - body.MinIndex() + 1) rx := jxon_load(StrGet(pdata, length, "utf-8")) DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(body))
return isObject(rx) ? rx : 0 }
JSON lib here
Run the script below and change your PTT button to a key you don't use in game.
I randomly chose PageUp as your PTT button for this example.
#IfWinActive, ahk_exe yourExeNameHere.exe *`::PGUP #IfWinActive
Replace yourExeNameHere.exe
with your program's exe name, and replacePGUP
with whatever key you set your PTT to earlier. Here's a List of Keys, Mouse Buttons, and Joystick Controls.
This rebinds your `
to PGUP
(or whatever key you choose) whenever your game is the active window.
That's the best way I can see doing this if you're very intent on having the tilde key be your PTT button without it sending the tilde key.
Groggyotter with another great post. To add to what he said, if your commands are sending too quickly for the system to accept them, look into SetKeyDelay command. If you need a breakdown of the milliseconds, read the sleep command info (tl;dr: 1 second = 1000milliseconds).
>I want to remap my keyboard to switch my page up key to be shift and my right shift key to be page up.
PGUP::Shift RShift::PGUP
Edit: Changed shift to rshift per your post's request.
It's doing exactly as it's told. Sending a click or lbutton means down and up.
You can tell it to do just down or just up by adding it after the button. {Lbutton Down}
or {LButton Up}
.
> So I need it to move to the spot,
Use MouseMove
>click and hold,
Send, {LButton Down}
>and then be able to move my mouse to aim with the click being held in until I release
You should still be able to do this. In my code, it's set to repeat the clicking action, not hold the button down. (That's how I thought you wanted it.)
I cleaned up your code and came up with this:
#SingleInstance, force return
2:: 4:: 6:: MouseGetPos, xStart, yStart if (A_ThisHotkey = 2) MouseMove, 1223, 917 if (A_ThisHotkey = 4) MouseMove, 1293, 736 if (A_ThisHotkey = 6) MouseMove, 1460, 639 while GetKeyState(A_ThisHotkey, "P"){ Send, {LButton Down} Sleep, 10 } Send, {LButton Up} MouseMove, % xStart, % yStart return
^x::ExitApp
Idk if it is possible with pure AHK vanilla, but I've found this tiny tool:
RBTray is a small Windows program that runs in the background and allows almost any window to be minimized to the system tray by:
first thing I would suggest is to abandon the concept of alt-tabbing to change focus, this is only good for humans who can use it in conjunction with an interface, or when there is no way for your program to know in advance what it's looking for. instead use commands like <code>winactivate</code> with named titles and classes to focus them directly.
you could also try a wysiwyg editor like Pulover's, though there's really no substitute for the manual. going through the 'basic usage and syntax' section of your manual index would help you out immensely here, and save hours of trial and error.
Try doing a multi-line and using SendInput instead.
Used your post as a long text example.
#SingleInstance, Force
:*:longtxt:: SendInput, % "I have a couple of strings bound to key combinations but whenever I enter them, they make typos 95% of the time and never type the thing in the right order." return
I would suggest to abandon the idea of clipboard pasting, it's always a last resort and this seems to be the weak link in your app. look into COM functions for word documents, this data can be extracted with object oriented code through your file system, in the same way you've implemented your output
see blackholyman posts in this thread, table parsing is explained in some detail here with nuggets I think are perfect for your use case. combine with string parsing for exact fields to harden your script
another positive side effect would be removing active restrictions for the user, doesn't matter what documents they have open when you no longer rely on the ui to get your data
soundset syntax is
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
So, your attempt to set it to device once was missing a comma and should read
Soundset, 6, microphone, , 1
EDIT: Also, Check out this script as it will help you identify if you are using the right device number. I just used that to set my mic (device 2 in my case) to 6. I then reran that tool to verify that it had indeed been changed.
> Is there a way to read the last line in a text file, untill a specific word is found?
Loop {
Loop, read, test.txt
last_line := A_LoopReadLine
if InStr(last_line,"login:")
break
}
MsgBox Found!
You can also use FileGetTime
to monitor when your logfile is updated and read it only when something changes.
read this first, all of it. probably the single most useful manpage for beginners to ahk, things need names if you want to interact with them, this explains how and why to use different handles for virtually every command in the language that has to indentify a window
You mean Hotstrings and Auto-Replace?
Tutorial if you're newer to AHK.
Example:
::btw::by the way
If you type btw
and then hit space/enter/period/etc... it'll automatically change it to by the way
.
Hotstrings are one of the main functions of AHK.
Only thing that irks me is that when you use Send to send a lot of keystrokes (say Space 72 or v 36), pressing a will not toggle off the script easily since the code is running serially. It isn't too hard to make those special cases run on a different thread using SetTimer.
#MaxThreadsPerHotkey, 2 #SingleInstance, Force
; If you want no key delay, use SendInput ; by uncommenting the line below. ; SendMode, Input
; If you want to have delay between keypresses, set a delay and ; press duration to your preference using the following command. ; The delay is 100 ms and the press duration is 10 ms below. ; https://autohotkey.com/docs/commands/SetKeyDelay.htm SetKeyDelay, 100, 10
return
a:: flag := !flag if flag { Loop { Send, {f down} Sleep, 1000 Send, {f up} Send, {Space 72} Send, {Escape} Send, i Send, {Down 2} Send, {Space} Send, {v 36} Send, {x down} Sleep, 4000 Send, {x up} Send, {Space} Send, {Escape 3}
} } else { Reload } return
https://autohotkey.com/docs/Hotkeys.htm#Intro
> You can use the following modifier symbols to define hotkeys (...)
^WheelDown:: MsgBox Scrolled down while holding control return
And to answer to that:
> just writing out WheelDown
Use Send {WheelDown}
next time, check:
https://autohotkey.com/docs/commands/Send.htm
> Key Names: The following table lists the special keys that can be sent (each key name must be enclosed in braces)
You can try doing this instead:
#z:: Send, Username123{!}{tab}Password123{!}{Enter} return
Alternately you can use this
#z:: SendRaw, Username123! Send, {Tab} SendRaw, Password123! Send, {Enter} return
This is thoroughly covered in the AHK documentation on the Send Command
Edit: Removed rogue backslash that infiltrated its way into the last part of the post.
You could use two RegExReplace commands to do this.
; Removes all characters in the second argument, add anything you need removed
Clipboard := RegExReplace(Clipboard, "[®℠©™]")
; Changes all occurrences of 2 or more spaces into single space
Clipboard := RegExReplace(Clipboard, " +"," ")
edit: Oops, fixed first expression, forgot the brackets
Great question!
It can be used to target windows using their class name instead of window name or process. You can read more about it here in the docs: https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class
As for when to use it over ahk_exe
I'm not sure. I don't think I've ever used it for that.
Your Send syntax is wrong.
To send a key it's Send, text
or if you need to send a special button like space you use Send, {BtnName}
.
BTW this:
Send, text
is the same as this:
Send, {t}{e}{x}{t}
and is the same as this:
Send, {t down}{t up}{e down}{e up}{x down}{x up}{t down}{t up}
As for your code, here's a rewrite that shows the actual steps without throwing the Ternary Operator at you.
#SingleInstance Force state := "Up" Return
*LControl:: If (state = "Up") state := "Down" Else state := "Up" SendInput, {Space %state%} Return
*F12::Exitapp
If you like hot, dirty, short code that works without an explanation, here's your whole script in 2 lines:
*LCtrl::Send, % "{Space " ((t := !t) ? "Down}" : "Up}") *F12::Exitapp
In Lintalist the snippet would look like this:
Small bowel: ● Disease location: [[choice=?Disease location|terminal ileum|jejunum|etc]] ● Enhancement pattern and wall thickening: [[Choice=?Enhancement pattern and wall thickening|mural stratification|homogeneous|thick|yes/no]] ● Length of disease: [[Input=Small Bowel: Length of disease (cm)]] ● Edema and restricted diffusion (MRI only): [[input=Edema and restricted diffusion (if yes, location)]] ● Stricture: [[Choice=?Stricture|present|luminal narrowing without upstream dilatation|none]] Colon: ● Disease location: [[choice=?Disease location|ascending|transverse|etc.]] ● Enhancement pattern and wall thickening: [[choice=?|mural stratification|homogeneous]] ● Length of disease: [[Input=Colon: Length of disease (cm)]]
I've built an example form builder based on "text" in the past, should get you going https://autohotkey.com/board/topic/107687-lintalist-searchable-interactive-lists-to-copy-paste-text/page-2#entry693068
after searching some more, i finally found what i needed. i'm gonna post it here incase anyone finds this post and want's it.
​
$RButton::
Loop
{ Click, R
sleep 10
If (!GetKeyState("RButton","p"))
break
}
Return