aI use AutoHotKey to remap a few keys, and that has been extremely useful. Example:
!t::
Send, ^t
return
That would intercept Alt-t key and send Ctrl-t instead.
I was wondering if there's a way to intercept an Alt-LeftMouseClick and send Ctrl-LeftMouseClick instead?
This maps ALT+LeftMouseClick to Ctrl+LeftMouseClick
!lbutton::send ^{click}
Turns out, I could do it with:
!LButton::
Send, {Control down}
MouseClick
Send, {Control up}
return
Related
I'm impressed with what AutoHotkey can do. How can I optimize that code? What do I need to know?
SetTitleMatchMode RegEx ;
::/act1::
Send {LControl down}
Send {LShift down}
Send {m}
Send {LControl up}
Send {LShift up}
Send {Left 3}
Send {LShift down}
Send {Home}
Send {LShift up}
Send {LControl down}
Send {c}
Send {LControl up}
WinActivate WidnowA
Send {LControl down}
Send {Home}
Send {LControl up}
Send {Down 1}
Send {Right 12}
Send {LControl down}+{v}
Send {LControl up}
Send {,}
Send {Space}
Send {LControl down}
Send {s}
Send {LControl up}
CoordMode, Mouse, Screen
x := 150
y := 1420
Click %x% %Y%
Send {Right 3}
return
I think that no need to describe the sections, but.. can I write it another (easiest) way?
Thanks
Along with the possible typo David found, you can condense a lot of your send commands into one line. Also, does it need to be left control and shift or will either do? I've written it below without specifying.
SetTitleMatchMode , RegEx
CoordMode, Mouse, Screen
::/act1::
Send , ^+m{left 3}+{home}^c
WinActivate , WindowA
Send , ^{home}{down}{right 12}^v{,}{space}^s
Click , 150 , 1420
Send , {right 3}
Return
As far as writing it an easier way, it will help to know what you're trying to accomplish. It's likely that what you're trying to do can be done more reliablely by manipulating controls directly instead of sending keystrokes.
I don't see a lot of room to optimize here as there isn't much repetition going on. If you had the same series of keystrokes being used, you could reduce repetition with a function. However, it does appear that you have a typo at "WinActivate WidnowA"
One possible improvement is changing your use of "Send" to "SendInput" which is "generally faster and more reliable".
When using three different methods of holding down the left mouse button:
Mouseclick, left, 0, 0, 1, , D, R
or
Send {LButton down}
or
Click down
the game I'm making a macro for logs me out complaining that I'm sending too many actions. I tested this by itself as a script, like:
F3::
Click down
return
So there's no chance other code is causing it.
I was wondering if there are any settings I can use (by settings I mean like CoordMode, Mouse, Screen) or any other solution to perhaps prevent whatever rapid event sending AHK is using to simulate a mouse button being held down. Is there any possible fix I can try? I'm open to testing any ideas.
Well, you could introduce a Sleep like so:
LButton::
while (GetKeyState("LButton", "P"))
{
MouseClick, left
Sleep, 100
}
return
Though I personally dislike binding the mouse click to behaviours via the same mouse click, as it can lead to results that are difficult to get out of.
Here's an example with a toggleable hotkey.
Insert::
SendInput, {LButton Down}
loop
{
Sleep, 100
if getkeystate("Insert", "p") ; Hold for a second as the Sleep will delay recognition.
{
SendInput, {LButton Up}
break
}
}
return
Edited per the comments:
Insert::
SendInput, {LButton Down}
KeyWait, Insert, D
SendInput, {LButton Up}
return
I am trying to build a very simple AutoHotkey script but it doesnt seem to be working. I've bought a keyboard with no Win key and no programable hardware layer so I am planning on using AHK to remap the Alt Gr key to the Windows key.
Can anypoint give me pointers to where I am going wrong.
<^>!l::
MsgBox Win L pressed.
return
<^>!r::
Send {# down}
Send {r down}
Send {# up}
Send {# up}
return
<^>!e::
SendInput #&e
return
Using your middle example, it'd be like so:
<^>!r::
SendInput, {LWin Down}r{LWin Up}
Return
You can use RWin or LWin per your preference since it really shouldn't matter at the software level.
I'm kinda new at this. I have a mouse with only 3 keys that I'd like to write a script for to allow me to use the right mouse button like a "browser back" key if clicked, while still retaining the original function if held for a longer period of time.
RButton::
sleep 400
GetKeyState, state, RButton
if state = U
send {Browser_Back}
else
send {RButton}
keywait, RButton
return
Currently, all my script above does now is activates the "browser back" function, regardless of time held down. I think there's a problem with the key being repeated at the send {RButton} line, but adding a $ to RButton:: didn't seem to help (if it was supposed to, idk.) If I replace the 3 "RButton" instances (not including the one on the send line) with a key on the keyboard, it works perfectly though. Help would be appreciated. Thanks.
Adjusted the code from BlackHolyMan's response to fix it. In case anybody was curious or wanted it, here it is:
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
{
send {Browser_Back}
return
}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Hi this may be just about what you need
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
send {Browser_Back}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Still some things you may need to fix as i did not test it for long...
I'm attempting to send three keys (Alt, Shift, Q) at same time using this script:
:*:pk:: ;
Send, {AltDown}{ShiftDown}{qDown}
return
When I run this is it does not release the keys, it seems like the Alt button remains pressed. After the above keys are pressed I then want to press the "q" character again (separately, not at same time).
How can I amend my script above to achieve this?
When using Down, you must also send an Up to the same key or else it will remain pressed. This can be achieved like this:
:*:pk::
Send, {Alt Down}{Shift Down}{q Down}{Alt Up}{Shift Up}{q Up}
Send, {q}