im pretty new to autohotkey.
Im trying to make something like this.
+q:: ( pressing shift+q to launch the macro )
send q
sleep
send w
sleep
send e
sleep
send r
sleep
send f
sleep
send +q
What happen with me is i keep spaming those buttons. And i want it to just stop after the last one, and not like "cancel" but just do nothing.
You don't know what you are doing, do you?
Put return at the end.
+q::
send q
sleep, 100
send w
sleep, 100
send e
sleep, 100
send r
sleep, 100
send f
sleep, 100
send +q
return
Related
In an fps I am trying to setup a hotkey such that when I am holding Lbutton (leftmouse), primary fire of a gun, and then tap RButton the LButton ceases and RButton commences. Ingame with no script, for other weapons, I get the desired result automatically. That is: I'm holding LButton, but if I also hold RButton 'after', the LButton ceases and the RButton's burst fire does its thing. However a different scoped weapon, with no script, freezes up when the above is done.
So I'm looking to, as soon as RButton is pressed, cease all user input of LButton until RButton's hotkey finishes.
~RButton
;Blockinput Mouse ;Send/Sendmouse
Send, {Click Left}{Click Right}{Click Left}
;BlockInput off
return
You can think of the Rbutton script as for a scoped rifle. Click Left activates scope, Click right fires it. Currently the desired behaviour only works when I completely remove my hand from LButton and then press RButton....I am also able to get ~LButton & ~RButton:: to work but that only covers the case when they r both first pressed at the exact same time, I want to cover the instance where LButton is pressed and held before RButton.
Ive tried applying blockinput, like seen above, had the UAC workaround to get it working, blocks certain things but doesnt seem to block any heldkeys when it is proc'd like the lbutton unless I'm missing something. If there was a "Freeze user input of LButton as soon as RButton procs, until RButton's script finishes" that would solve the problem I would think. I tried adding sleep delays, but they dont seem to help. The issue seems to be that LButton, when held, continues to proc when RButton first activates.
I used the below while holding LButton, and the sound DOES proc, so this must be possible to script.
*RButton::
Soundbeep
return
EDIT:
;code here works but only with that 100 sleep where i have to remove my hand from pressing the lbutton within 100ms of pressing rbutton.
*RButton::
GetKeyState, state, lbutton, p
if (state = "D")
{
soundbeep
send {Click Left Up}
sleep 100
;i need to actually disable the previous keypresses from it
}
Send, {Click Right}{Click Left}{Click Right}
return
From what I understood from your question, you don't really need to block user mouse input so much as Sending a Left MouseUp command if the Left mouse button was held down. I was having difficulty understanding what the end goal you were looking for was, but I wrote this based on what I was able to understand:
#SingleInstance Force
*RButton::
Soundbeep
If (getKeyState( "lbutton", "p" )){
Click, Left, Up
Send, {Click Left}{Click Right}{Click Left}
} else {
Send, {Click Left}{Click Right}{Click Left}
}
return
esc::ExitApp
UPDATE:
Based on the clarification from the comments of the question, this should work. Understood functionality: If the right mouse button is clicked while the left mouse button is held down, release the LMB, but do not suppress the RMB input.
*~RButton::
If (getKeyState( "lbutton", "p" ))
Click, Left, Up
return
UPDATE 2:
Now releasing the LMB before the RMB is pressed. I have a feeling that whatever game that you are playing will not be able to detect zero-tick switches between keystates, so I included a Sleep function that you can fine-tune/ remove as needed.
*RButton::
If (getKeyState( "lbutton", "p" )){
Click, Left, Up
Sleep 100
}
Click, Right, Down
KeyWait RButton
Click, Right, Up
return
I've written a Autohotkey script to auto-complete print statement in java
System.out.println("");
by clicking s and then Tab and jump to next line when cursor is between quotation marks by clicking Shift + Enter as follows
:*:s`t::System.out.println("");{left}{left}{left}
+Enter::
ClipSaved := ClipboardAll
Loop
{
clipboard =
Send, +{Right}
Send, ^c
ClipWait , 0.2
StringRight := InStr(Clipboard,OutputVar, 1)
If OutputVar = {;}
Send ^v
Send {Right}
Send {Right}
Send {Right}
Send {Enter}
break
}
clipboard := ClipSaved
Return
The problem here is it works good when I type s and then Tab and when clicking Shift + Enter jumps to new line. But if I type anything between quotations and then hit Shift + Enter it jumps to new line but then onwards the auto-complete is not working i.e., I'm not getting print statement when typing s and then Tab.
The image of error is attached for illustration. You can copy/paste the code and tell me where the error is, as I'm unable to figure it out.
If you want to trigger a hotstring after you typed something, you need to use the question mark option. Try this:
:*?:s`t::System.out.println("");{left}{left}{left}
I want to change the use of Ctrl to Spacebar for three commands in a game but not for everything cause then I can't use space to communicate. The normal commands are Ctrl+q, Ctrl+w, Ctrl+e, Ctrl+r and Control+RButton (right mouse). Right now I'm usng Space::Ctrl, however I have tried different solutions with no result.
[EDIT/]
#MCL Ok. I looked at the forum thread you posted and tried the code below which sorta worked. It sent the keys how I wanted, but each shortcut triggered all shortcuts that followed it. For example space+e triggers space+e, space+r and space.
Also, Spacebar still didn't work. I added the Space::Space later and I can get a text space only by using the Space+(q, w, e or r) shortcuts.
SendMode Input
SetKeyDelay ,0,30
#IfWinActive ahk_class RiotWindowClass
Space & q::
Send {Ctrl down}
Sleep 30
Send {q down}
Sleep 30
Send {q up}
Sleep 30
Send {Ctrl up}
Space & w::
Send {Ctrl down}
Sleep 30
Send {w down}
Sleep 30
Send {w up}
Sleep 30
Send {Ctrl up}
Space & e::
Send {Ctrl down}
Sleep 30
Send {e down}
Sleep 30
Send {e up}
Sleep 30
Send {Ctrl up}
Space & r::
Send {Ctrl down}
Sleep 30
Send {r down}
Sleep 30
Send {r up}
Sleep 30
Send {Ctrl up}
Space & RButton::
Send {Ctrl down}
Sleep 30
Send {RButton down}
Sleep 30
Send {RButton up}
Sleep 30
Send {Ctrl up}
Space::Space
#IfWinActive
[/EDIT]
Found it. I needed to add the returns.
#NoEnv
SendMode Input
#InstallKeybdHook
#UseHook
#IfWinActive ahk_class RiotWindowClass
Space & q::
Send {Ctrl down}
Sleep 30
Send {q down}
Sleep 30
Send {q up}
Sleep 30
Send {Ctrl up}
return
Space & w::
Send {Ctrl down}
Sleep 30
Send {w down}
Sleep 30
Send {w up}
Sleep 30
Send {Ctrl up}
return
Space & e::
Send {Ctrl down}
Sleep 30
Send {e down}
Sleep 30
Send {e up}
Sleep 30
Send {Ctrl up}
return
Space & r::
Send {Ctrl down}
Sleep 30
Send {r down}
Sleep 30
Send {r up}
Sleep 30
Send {Ctrl up}
return
Space & RButton::
Send {Ctrl down}
Sleep 30
Send {RButton down}
Sleep 30
Send {RButton up}
Sleep 30
Send {Ctrl up}
return
Space::
Send {Space}
return
#IfWinActive
Regarding : "Space will only work as text and won't work as the shortcut to center camera on your character."
Try using SendMode Play instead of SendMode Input.
SendPlay's biggest advantage is its ability to "play back"
keystrokes and mouse clicks in a broader variety
of games than the other modes.
-- From the documentation for SendPlay.
For further reading about Send mode settings, tradeoffs & abilities, check out the documentation for SendMode .
Regarding : SetKeyDelay
SendMode Input will not be effected by SetKeyDelay:
Note: SendInput ignores SetKeyDelay
because the operating system does not support
a delay in this mode.
-- From the documentation for SendInput
Additional information :
One thing to be aware of when using Custom Combinations (docs) (i.e. using non-modifier keys for hotkey combinations):
when you defined the first Space & otherkey::, the Space key becomes a "prefix key", which means it loses its native function. This necessitated the final hotkey you defined in your example :
Space::
Send {Space}
return
A note of caution : this hotkey (which restores functionality to the prefix key) fires when Space is released. And it will not fire if any other key is pressed between Space down and Space up.
Your script works as expected otherwise in Notepad++ (replacing the Send lines with MsgBox for debugging).
So this is likely an issue with the game picking up AHK's sent space key.
Try debugging by making a simple script which does nothing other than sending Space to the game using different SendModes.
I am trying to automate export of Lotus Notes emails to Microsoft XPS documents so that I'll be able to search through them.
Now I would like to automate the export by using AutoHotKey to print and select 'Microsoft XPS document' in the printer name list.
I have the following script:
; F2 is my chosen HotKey that will trigger the script, starting with a CTRL-P
*F2::^p
; type 'm' to choose 'Microsoft XPS Document Printer'
Send m
{enter}
which opens the print view window, but does not select the printer, although manually typing 'm' works. I tried a sleep but did not work either.
First of all, your second command is never executed. When you place a command at the same line as your initiating code. Even when the second command was executed it could be too fast. try this:
F2:: ; Use the F2 key (I would use F1 as I never use the help key)
Send, ^p ; Send Control P to print
Sleep, 1000 ; wait 1 second (or less) for print dialoguebox
Send, m ; Select printer type
Sleep, 100 ; Wait 0.1 sec. before pressing enter
Send, {Enter} ; Press enter
Return ; End this command
Regards,
Robert Ilbrink
I have a small task I would like to automate with Autohotkey and it looks like it is more or less directly transferable to autohotkey syntax:
1. Ctrl+v
2. Alt+tab
3. Click certain link in a window (no combo-key for this but it's always in the same place)
4. Enter (carriage return)
5. Alt+s
6. Ctrl+v
7. Enter
Now it would be nice to map this combo to something else e.g. Windows Key+Space.
What I have got so far is:
0. SetWinDelay 100 (using a connection to an remote computer)
0. SetKeyDelay 0
1. Send, ^c
1. ClipWait, 0.1
2. Send, {Alt down}{tab}
2. Send, {Alt up}
3. ?????
4. Send, {enter}
5. Send, !s
6. Send, ^v
7. Send, {enter}
Is this approximately right? Anyone up for helping me fix it or filling in the holes, so to speak :)
Another alternative to step 3, 4 and 6 would be to simply loop though the contents of the clipboard (a number string) and sending each letter of the string to keypresses? Maybe this would be the easier way
If you want to "click" on a certain position, to open a menu, you can first right click on your AutoHotKey icon and open the "window spy". This window spy will show you the mouse position. Yo can use the mouse positions to perform your actions in the active application.
Example:
SoundBeep 1000, 300 ; Wake up user
SplashTextOn, 200, 100, Script Preparations, Please Click on the person icon link. ; Show new Instructions text
WinMove, Script Preparations,, (A_ScreenWidth/2)+150, (A_ScreenHeight/2)+200 ; Move the window with the name "Script Preparations" Down and Right on the main screen
KeyWait, LButton, D ; Wait for LeftMouseButton click Down
MouseGetPos, xposE ,yposE ; Store the position where the mouse was clicked (Employee)
MouseClick, left, %xposE% ,%yposE%, 2 ; Perform a double mouse click on the captured mouse location
SplashTextOff ; Remove Text box
In this case, I first ask the user to manually click on the right location. This is only required when the position to click changes WITHIN the active window (variable tiles within the active window). Once you have the position stored, you can re-use it all throughout your script.
b.t.w. instead of using Alt+Tab, I suggest using this:
settitlematchmode, 1 ; Set search in title to start with....
settitlematchmode, Fast ; Slow is not required here. Slow is only required when hidden text needs to be found.
SwitchWindow("Microsoft Excel - 1 QRM Upload and Change Template") ; Activate the
window with the title: Microsoft Excel - 1 QRM Upload and Change Template
You could even use someting like this:
SetTitleMatchMode, 2 ; Ensure that the Title Match mode is set to 2: Find anywhere in the title
SetTitleMatchMode, Fast ; Ensure that the Title Match mode is set to FAST
winactivate, %WindowName% ; Activate the window with the title stored in the variable WindowName
WinWaitActive, %WindowName%, , 5 ; Wait up to five seconds for the screen
if ErrorLevel ; Execute this when the window is not activated within 5 seconds
{ ; Start-If Wait failed
SoundBeep 1000 , 1000 ; Warn the user
MsgBox,4097,Time Out, Script timed out while waiting for %WindowName%.`n`rYou Must manually activate %WindowName% and then continue the script by pressing OK. ; Message to user
IfMsgBox, Cancel ; Do when the user clicked on Cancel
{ ; Start-If User clicked Cancel
ExitApp ; Exit this program when the user clicked on Cancel
} ; End-If User clicked Cancel
WinWaitActive, %WindowName%, , 5 ; Try to activate the window AGAIN
if ErrorLevel ; If window can't be found
{ ; Start-If window can't be found
MsgBox,4096,Exit, %WindowName% still NOT Active. ; Warn user
ExitApp ; Exit this program when the expected window is still not found
} ; End-If window can't be found
} ; End-If Wait failed
Regards,
Robert Ilbrink