AutoHotKey Key Combinations (remap) for key modifiers - keyboard-shortcuts

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.

Related

autohotkey: Cancel RButton user input after LButton pressed

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

Autohotkey: Repeating keypress with key modifier held down

How to rebind a key chord with Ctrl so that it repeats on multiple presses, while Ctrl is held down?
Example: I'm expertimenting with binding Ctrl+Space to Backspace.
^Space::Send {BackSpace}
When I now press Ctrl+Space correctly Backspace is sent and deletes the last character. I want now to keep Ctrl down and delete further characters with multiple Space strokes.
The trick is to use SendInput and release Ctrl:
^Space::sendinput {Ctrl up}{BackSpace}

How To Send Lower Caps String On VB.NET Using Sendkeys.send Whihe Shift key pressed

I want to sendkey "hello" using sendkeys command in vb.net but it sending "HELLO" because shift button is true.
Now How to send "hello" in lower case when shift key is true...
Try turning caps lock on using keybd_event in user32.dll. With caps lock on, you can "hold down" shift while "typing" lower case letters. Send Keys mimics using the keyboard, so you have to think about how you would do this with an actual keyboard.
See How do I toggle Caps Lock in VB.NET?

Making a macro for more than one key press

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

Autohotkey Win XP automating small task

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