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
}
Related
As the title says, I've had trouble finding a way for my script to only block keyboard inputs during my script. Is there a method that I've overlooked to do this? Here's my code for reference:
toggle = 0
*xbutton1::
{
if GetKeyState("d", "P")
{
if GetKeyState("w", "P")
{
BlockInput On ;enabled
Send, {d up}
Send, {w up}
Send, {a down}
Send, {s down}
Send, {K}
BlockInput Off ;disabled when completed with the above actions ^ so no key inputs interfere
Sleep, -1
Send, {a up}
Send, {s up}
Send, {d down}
Send, {w down}
return
}
Thanks! I'd appreciate any info or tips.
You can create a function to only block keyboard input:
; Press F1 to block keyboard input for 10 seconds:
$F1::
BlockKeyboard("On")
Sleep, 10000
BlockKeyboard("Off")
return
BlockKeyboard(state){
Loop, 512
{
Key := Format("SC{:X}",A_Index)
If (state = "On")
Hotkey, *%Key%, KeyboardKey, On UseErrorLevel
else
Hotkey, *%Key%, KeyboardKey, Off UseErrorLevel
}
KeyboardKey:
return
}
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
I can see that Ctrl+Alt+Delete is not possible with AutoHotkey, but what about just Ctrl+Alt?
Things I've tried:
; 1
#+y::
Send, {Ctrl}{Alt}
return
;2
#+y::
Send, {Ctrl down}
Send, {Alt down}
Send, {Alt up}
Send, {Ctrl up}
return
;3
#+y::
Send, {LCtrl down}
Send, {LAlt down}
Send, {LAlt up}
Send, {LCtrl up}
return
;4
#+y::
Send, !^
return
;5
#+y::
Send, {ctrl down}{alt down}{2}{alt up}{ctrl up}
return
Any ideas?
The below will do what you want. It's also recommended you use SendInput going forward.
#+y::
SendInput, {Ctrl Down}{Alt Down}{Ctrl Up}{Alt Up}
Try to specify the left or right ALT or CTRL keys
#+y::
Send, {LCtrl}{LAlt}
return
hi again my script is almost complete but there is problem in executing hotkeys
Problem : when i hit Alt + Space it is conflicting with Space .. they are overlaping each other or executing both hotkey which makes custom modifier keys unstable or not working as intented
here is the code:
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
#if, GetKeyState("MButton")
Lbutton::
RButton::
return
#if
i want to add a rule if alt + space keycombo is held down this hotkey will not work
meaning i want to disable Script A if Script B is executed
Script A ::
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
Script B ::
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
thank you in advance
Wrap the space:: part in #If, !GetKeyState("Alt")
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
#if, !GetKeyState("Alt")
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
#if, GetKeyState("MButton")
Lbutton::
RButton::
return
#if
space::
Hotkey_Alt_Space = 0 ; disabled
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
Hotkey_Alt_Space = 1
return
!space::
If (Hotkey_Alt_Space != 0) ; enabled
{
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
}
return
i was help by someone at AHK forum thank you for time the problem is solve i am able to customize my rotate and pan navigation at sketchup
I want my autohotkey script to have mouse clicks once i press shift+3 keys on my keyboard, ignoring the shift key being held down.
For example I have attempted it in this way:
+3::
SetMouseDelay, 0
MouseGetPos, xpos, ypos
Send {Shift Up}
BlockInput, on
Send {Shift Up}
MouseClick, right, uhxpos, uhypos
Sleep, 41
MouseClick, left, yourxpos, yourypos
MouseMove, xpos, ypos
BlockInput, off
return
And even tried to wait once the shift is physically released, still no success;
+3::
SetMouseDelay, 0
MouseGetPos, xpos, ypos
KeyWait, +
MouseClick, right, uhxpos, uhypos
Sleep, 41
MouseClick, left, yourxpos, yourypos
MouseMove, xpos, ypos
return
Would appreciate any help, thanks.
Try to send {Shift Down} before {Shift Up} and maybe you should replace Send with SendInput:
+3::
MouseGetPos, xpos, ypos
SetMouseDelay, 0
Sleep, 100
SendInput, {Shift Down}
SendInput, {Shift Up}
MouseClick, right, uhxpos, uhypos
Sleep, 41
MouseClick, left, yourxpos, yourypos
MouseMove, xpos, ypos
Return
use KeyWait, Shift instead of KeyWait, +