'how to I loop every x seconds to check the caps key status?

this is the only code that I have in my .ahk file

if getkeystate("capslock","t")

{
/:: Send {0}
u:: Send {1}
i:: Send {2}
o:: Send {3}
j:: Send {4}
k:: Send {5}
l:: Send {6}
m:: Send {7}
,:: Send {8}
.:: Send {9}
}

else

return

the problem is that it detects capslock always on(so it always changes uiojklnm./ to 1234567890) , even when it's off so , how do I fix the problem ?

question n 2 (not related to the first one)

this script works completely fine

!w:: Send {Up}
!a:: Send {Left}
!s:: Send {Down}
!d:: Send {Right}

there is just one problem, when I press ALT + TAB and then I press ALT + s (I don't leave the finger from alt) the script does not work, it's because I don't leave the finger from the ALT key, so ahk does not detect ALT+s, so is there a way to do something like this?

while(! is pressed){
if (w is pressed){
Send {Up}
}
....
}

thanks a lot in advance



Solution 1:[1]

To create context-sensitive hotkeys and hotstrings use the #If directive:

#If getkeystate("capslock","t")

    /:: Send 0
    u:: Send 1
    i:: Send 2
    o:: Send 3
    j:: Send 4
    k:: Send 5
    l:: Send 6
    m:: Send 7
    ,:: Send 8
    .:: Send 9

#If ; turn off context sensitivity

Your other issue is not related to this one und should be asked in another question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3419297