i'm tring to get a key held for 300ms and active some action,but it keeps activing that action over and over again if i keep holding the key.
i've tried to use $ and A_TimeSincePriorHotkey,all didn't help.
$r::
if (A_PriorHotkey = "r" and A_TimeSincePriorHotkey < 100)
return
keywait, r, T0.3
if (ErrorLevel = 1)
{
GetKeyState, Mode, NumLock, T
if (Mode="U")
SetNumLockState ON
else
SetNumLockState OFF
send {r up}
}
else
send {r}
return
Try this out. The only adjustment is adding the KeyWait, r This will cause the script to wait until the hotkey is released so that it's not constantly activating while the hotkey is pressed down as you described.
$r::
if (A_PriorHotkey = "~r" and A_TimeSincePriorHotkey < 100)
return
keywait, r, T0.3
if (ErrorLevel = 1)
{
GetKeyState, Mode, NumLock, T
if (Mode="U")
SetNumLockState ON
else
SetNumLockState OFF
KeyWait, r
}
else
send {r}
return
Related
I just want this loop to work when LButton is down and stop when LButton is up.I
The code works when LButton is down but it continues working when i lift my finger off the left click button.
mem:=0
~*LButton::
Sleep, 100
KeyWait, LButton, T0.10
If ErrorLevel = 1
{
While GetKeyState("LButton","P")
Loop {
GetKeyState, state, LButton, P
If state = U
Break
MouseGetPos, xpos, ypos
if (xpos > mem) ;moved right
{
send, {a down} ;send key
mem:=xpos
}
else
send, {a up}
if (xpos < mem) ;moved left
{
send, {d down}
mem:=xpos
}
else
send, {d up}
Sleep, 100
}
}
return
You case is very similar to the example of the usage of the while loop.
If you look at that you can see, you don't need the Loop inside the while. Just have
while GetKeyState("LButton")
{
; Your code here:
MouseGetPos, xpos, ypos
if (xpos > mem) ;moved right
{
send, {a down} ;send key
mem:=xpos
}
else{
send, {a up}
}
if (xpos < mem) ;moved left
{
send, {d down}
mem:=xpos
}
else{
send, {d up}
}
Sleep, 100
}
I am trying to make a script that when press x to cut, c to copy and v to paste if the ScrollLock is on.
Here is my script that is not working, it will perform cut, copy and paste no matter ScrollLock is on or off.
~ScrollLock::
KeyWait, ScrollLock
GetKeyState, ScrollLockState, ScrollLock, T
If ScrollLockState = D
{
x:: Send, ^x
c:: Send, ^c
v:: Send, ^v
}
And for the script below, I cannot type x, c and v when ScrollLock is off, but can cut, copy and paste when ScrollLock is on.
~ScrollLock::
KeyWait, ScrollLock
GetKeyState, ScrollLockState, ScrollLock, T
x::
If ScrollLockState = D
{
Send, ^x
return
}
c::
If ScrollLockState = D
{
Send, ^c
return
}
v::
If ScrollLockState = D
{
Send, ^v
return
}
You can do it in the following way:
#If GetKeyState("ScrollLock", "T")
x::Send, ^x
c::Send, ^c
v::Send, ^v
#If
I'd like to remap my windows key to something else, but also I'd like to keep all windows key based shortcut.
In pseudo code it would be something like this:
when LWin Down
until LWin Up
if not LWin down
abort
else
execute command
Release the left windows key within 0,3 seconds after pressing it, to do something else (e.g. to send a):
~LWin::
KeyWait, LWin
return
~LWin Up::
Send {LWin Up}
If (A_PriorHotKey = "~LWin" AND A_TimeSincePriorHotkey < 300)
Send, a
; else ; another action after long press (not recommendet)
; Send, b
return
EDIT:
Try also this:
LWin up::
If (A_PriorKey = "LWin")
Send a
return
; In this case its necessary to define a custom combination by using "&" or "<#"
; to avoid that LWin loses its original function as a modifier key:
<#d:: Send #d ; <# means LWin
So in this game im moving my charachter with the WASD keys, but if i hold down the A and D key at the same time,
the game register that as a forward movement (W key |) so the charachter starts to move forward instead of the strafe actions (Left) \ (right) /.
So i need a code which is prevents the A and D key simultaneous pressing.
CHECK THIS GIF, SO U CAN SEE WHAT I MEAN!
I want A and D override each other (Im not using the W key), because if i hit both A and D at the same time my character moves forward, not like this \ /
and i want to avoid the forward movements.
I want insantly changed fast Left \ and Right / strafing only.
Here is the code what i got so far:
~a::
If (GetKeyState("d", "p"))
{
Send {d up}
d = 0
}
Return
~d::
If (GetKeyState("a", "p"))
{
Send {a up}
a = 0
}
Return
a up::
If (d)
{
Send {d down}
d = 0
}
Return
d up::
If (a)
{
Send {a down}
a = 0
}
Return
Basicly this code almost working.
The problem is if i don't change the numbers i can't change directions continuously i need to let go the keys. It stops after 1 direction change. If i change the numbers its working, but after a few direction change its getting toggled either left or right. Even if i let it go its moving left or right....
Any ideas? thx
This should work. Try it and let me know.
$*a::
$*d::
SendInput, {a Up}{d Up}
StringReplace, hk, A_ThisHotkey, % "$*"
SendInput, {%hk% Down}
KeyWait, % hk
Send, {a Up}{d Up}
return
EDIT: You can play around with the code below. Maybe it will help you out
#SingleInstance, force
#Persistent
#NoEnv
#MaxThreadsPerHotkey, 1
~a & d::
~d & a::
Send, {a up}
key := "d"
SetTimer, pressdown, 10
return
~d::key := "d"
~a::key := "a"
~a up::key := "d"
~d up::key := "a"
pressdown:
if GetKeyState(key, "p")
{
SendInput, {%key% down}
SetTimer, pressdown, 30
}
else {
SetTimer, pressdown, Off
SendInput, {%key% up}
}
return
This script cannot allow A, or D to be simultaneously pressed.
I'm looking to use AutoHotKey to modify the functionality of my shift keys. The functionality is described in Steve Losh's Blog entry here. Specifically, I'd like my shift keys to do the following:
If LShift or RShift is pressed and released in under 300 ms with no other keys being pressed in between, send ( or ), respectively.
If LShift and RShift are "rolled" together (press LShift, press RShift, release LShift, release RShift, etc.) in under 300ms, send () or )(.
If a shift key is used improperly (LShift and S, RShift and K, etc.) then nothing happens.
I've been having issues with the 300ms requirement and the "rolling" functionality. Specifically, I'm having issues with only being able to detect when the key is released due to the hotkey combos such as:
LShift & 0:: return
This is where I'm at so far:
LShift::
Send {LShift Down}
KeyWait, LShift
Send {LShift Up}
if (A_TimeSinceThisHotkey < 300){
if (A_PriorKey = "LShift")
{
Send {)}
}
}
return
I don't see a reason to use a 300 ms timeout anyway, it seems unreliable and unnecessary.
Have a look at this commented code, it is short and efficient, and seems to meet all of your requirements:
LShift::Send, (
RShift::Send, )
LShift & RShift:: Send, ()
RShift & LShift:: Send, )(
/* Put your unwanted combinations here
* and let them do nothing
*/
LShift & q::return
RShift & y::return
Edit:
Since LShift and RShift already are prefix hotkeys, I left out the trick described here.
MCL's answer is close but when I tested it I found that shift-clicking didn't select text. Here's a version with a passthrough to allow shift-clicking to work.
;shift to parens
LShift::Send, (
RShift::Send, )
LShift & RShift:: Send, ()
RShift & LShift:: Send, )(
;passthrough for shift-click
LShift & LButton::
Send, {LShift Down}{LButton}
Send, {LShift Up}
RShift & LButton::
Send, {RShift Down}{LButton}
Send, {RShift Up}
I don't think the 300ms timeout is possible without either very deep understanding of autohotkey's implementation or actual modification to autohotkey. When I tried to get it to work (using http://www.autohotkey.com/board/topic/98742-remapping-shift-key/) I found that A_PriorHotkey was not consistently populated. I don't think that variable was meant to work with modifier keys this way.
I felt compelled to figure this one out. Here you go!
I basically created a hotkey for every Shift + Letter key combination in order to send the correct key case and also set the Abort value. The Abort value is then referenced whenever one of the Shift keys is pressed in order to determine whether or not to send the corresponding ( or ).
The "Rolling" was accomplished by creating a Hotkey for LShift + RShift (and the opposite). It then looks to see which key is released first to determine () or )(.
Accept if this was what you were looking for!
Loop 26
{
Hotkey, % "~LShift & " Chr(A_Index+96), LetterKey ; Hotkeys for A-Z
Hotkey, % "~RShift & " Chr(A_Index+96), LetterKey ; Hotkeys for A-Z
}
Return
RShift::
LShift::
Abort := 0
keyDown := A_TickCount
Keywait, % A_ThisHotkey
duration := A_TickCount - keyDown
If (duration < 200) and (Abort = 0)
SendInput % (A_ThisHotkey = "LShift") ? "(" : ")"
Send {LShift Up}
Return
RShift & LShift::
LShift & RShift::
Keywait, LShift
If GetKeyState("RShift", "P")
{
Keywait, RShift
Send ()
}
Else
Send )(
Return
LetterKey:
SendInput, % "+" SubStr(A_ThisHotKey, 0, 1)
Abort := 1
Return
EDIT:
Hmm, I seem to be having the same problem as you. I always get a duration of 0 due to the hotkeys.
I found and modified this script on the AutoHotKey Forums. (The original script was prone to type "K(" when you meant to type "K" if you type too quickly, so I've modified it so that shouldn't happen any more)
$LShift Up::send, % getkeystate("LShift") ? "{LShift Up}" : ""
$RShift Up::send, % getkeystate("RShift") ? "{RShift Up}" : ""
~$LShift::
KeyWait, LShift, T0.1 ; wait 100ms to check shift state
if (A_PriorKey = "LShift")
{
send, % getkeystate("LShift") ? "{LShift Down}" : "("
}
KeyWait, LShift
return
~$RShift::
KeyWait, RShift, T0.1 ; wait 100ms to check shift state
if (A_PriorKey = "RShift")
{
send, % getkeystate("RShift") ? "{RShift Down}" : ")"
}
KeyWait, RShift
return