How can I send a keys default (from hardware) behavior in its own key definition. I mean this code:
vcerc = 0
+c::
vcerc := !vcerc
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
kkey = 0
$k::
if vcerc {
kkey := !kkey
if kkey
SendInput {k down}
else
SendInput {k up}
}
else {
Send, K
}
Return
In the end part Send, K It sends the word K. I am in a multi language environment which means if I switch to the other, This key still sends K rather than sending the one that is for the second language (assume ن).
How can I make this send the default? (From hardware with no matter what the language is)
Two things that seem off to me: 1) Your initial kkey declaration will never get hit since it falls after a hotkey (and a return). Declare your variables at the top. 2) if kkey is true, your script has it holding down the k button indefinitely. Is this expected? 3) Your only looking for lowercase k's but sending uppercase k's. Is this expected?
At any rate, this example should point you in the right direction.
vcerc = 0
kkey = 0
+c::
vcerc := !vcerc
return
$k::
{
if (vcerc) {
kkey := !kkey
if (kkey) {
msgbox, k down ; SendInput {k down}
} else {
msgbox, k up ; SendInput {k up}
}
} else {
Send, K
}
}
Related
I have problems with an AutoHotKey script. When I press F1, the left mouse button is held but A is also pressed. Does anyone know how I can fix this?
#MaxThreadsPerHotkey, 2
Toggle := 0
Toggle2 := 0
F1::
Toggle := !Toggle
If (Toggle){
Click, Down
} else {
Click, Up
}
F2::
Toggle2 := !Toggle2
If (Toggle2){
send {a down}
} else {
send {a up}
}
You need to tell autohotkey that you are done writing the code that should be executed when a hotkey is pressed by putting a Return after the last part you want to execute.
From the docs:
Returns from a subroutine to which execution had previously jumped via
function-call, Gosub, Hotkey activation, GroupActivate, or other
means.
So for your script:
#MaxThreadsPerHotkey, 2
Toggle := 0
Toggle2 := 0
F1::
Toggle := !Toggle
If (Toggle){
Click, Down
} else {
Click, Up
}
return
F2::
Toggle2 := !Toggle2
If (Toggle2){
send {a down}
} else {
send {a up}
}
return
I'm making a macro of a game, and I tried a different thing, and now it doesn't seem to be working. I added if Lf := 1 and if Rg := 1 which are variables to represent the radio indicator. Here's the code:
F9::
toggle :=!Toggle
if (toggle)
{
SetTimer, Repeat, 100
Repeat()
}
else
SetTimer, Repeat, Off
return
Repeat()
{
Click, 920, 885
Sleep, 200
if (Lf := 1)
{
Click, 755, 530
Sleep, 200
Click, 550, 530
}
else if (Rg := 1)
{
Click, 1165, 530
Sleep, 200
Click, 1370, 530
}
Sleep, 200
Send, {Space Down}
Sleep, %MilSecOne%
Sleep, %MilSecOne%
Send, {Space Up}
Sleep, 200
}
It doesn't work as I expected.
The := operator is used to assign a value (which will be the result of an expression) to a variable.
So right now what you're doing, is assigning the number 1 to your variables, and then checking with the if-statement if the value of that variable evaluates to true.
(And it always will, non-zero numbers evaluate to true)
You're looking for the = operator.
In an expression (which is what your if ( ) -statement is) it compares values, rather than assigns text to a variable, which is what it does in a legacy statement.
So, change
if (Lf := 1)
else if (Rg := 1)
to
if (Lf = 1)
else if (Rg = 1)
Edit:
I'm also noticing that the variables Lf and Rg doesn't seem to exist?
At least not in that function's scope.
I hope they're defined as super-global somewhere else.
Otherwise there's no way that code is going to work.
trying to make a toggle-able loop, seems to be not sending e at all, help please?
myvar := false
k::
myvar := true ? false : true
return
while (myvar)
{
Send, e
Sleep 100
}
Here is my suggestion:
k::SetTimer, SendLetterE, % (Toggle:=!Toggle) ? 100 : "Off"
SendLetterE() {
Send, e
}
You can assign another key to pause / resume. In this case k will toggle and F12 will run indefinitely (so just use k to toggle).
k::
Hotkey, F12, toggle
return
F12::
while(true)
{
Send, e
Sleep 100
}
Could also try Loop instead of while(true)
k::
pause, toggle
F12::
Loop,
{
Send e
Sleep, 100
}
return
referenced from AutoHotkey forum.
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 playing a game and it acts wonky when I press 3 buttons at the same time. I need the resulting input of holding down "A S D" to be only "S".
Something like
#SingleInstance
if getkeystate("a")
if getkeystate("s")
if getkeystate("d")
input "s"
A simple, but perhaps not so short combination of hotkeys and their up variants will do the trick. This script works like you intended, but only with buttons a and s. When s is held down, a does nothing. When s is not held down, a acquires its previous state.
#SingleInstance, Force
SetBatchLines, -1
global a_down = false
global s_down = false
a::
a_down = true
if( %s_down% = true )
return
Send, {a down}
return
a up::
a_down = false
if( %s_down% = true )
return
Send, {a up}
return
s::
s_down = true
if( %a_down% = true )
Send, {a up}
Send, {s down}
return
s up::
s_down = false
if( %a_down% = true )
Send, {a down}
Send, {s up}
return
In the spirit of StackOverflow, I will not post the complete script that will work with all three keys. That is left as an exercise to the reader.
I need the resulting input of holding down "A S D" to be only "S".
By "Input" you mean a Send command?? Please see Beginner tutorial - hotkeys and hotstrings.
If your task would be to behave A+S like S, you'd use
a & s::
send s
return
But you're asking for three keys which needs some workaround
#if getKeyState("d")
a & s::
send s
return
#if
or
a & s::
if getkeystate("d")
{
send s
}
return