1
votes

I have an autohotkey script that treats (h,j,k,l) buttons like (left,down,up,right) when CAPSLOCK is pressed.

However, when I press caps and a button (h,j,k,l) too quickly it just outputs the letter.

Is there a way to reduce this "lag"? Could this be done easily in another language such as c or c++?

I'm also not sure what all of this code does, as part of it is clipped from the web.

#Persistent
#SingleInstance, Force
SetKeyDelay, -1
CoordMode, Tooltip, Screen
modal =
context =
num =

SetTimer, vim, 100

; Disable CAPSLOCK
$CAPSLOCK::
return

$+CAPSLOCK::
return


vim:
While GetKeyState("CAPSLOCK", "P")
{
    vimize()
    if modal !=
      Tooltip, %context%: %num%, 60, 10
    else if num !=
      Tooltip, %num%, 60, 10
    else
      Tooltip
    SetTimer, vim, off
} 
modal =
num =
unvimize()
SetTimer, vim, on
Tooltip
Return

vimize()
{
  Gui 11:Show, Minimize, vimOn ; Hide,
}

unvimize()
{
  Gui 11:Destroy
}   

#IFWinExist vimOn

h::Send, {Left}
j::Send, {Down}
k::Send, {Up}
l::Send, {Right}

; ===== SubRoutines =====

GetLineSelection:
   Send, {Home}{Shift Down}{End}{DOWN %num%}{Home}{Shift Up}
Return

Run_Mode:
   Send, ^%modal%
   ;Send {Left}{RIGHT}
   num =
   modal =
return
1

1 Answers

0
votes

I couldn't find a way to improve performance, but I did rewrite the entire script and it works flawlessly now.

I used suspend instead this time.

Suspend On

;===Navigate
h::Left
j::Down
k::Up
l::Right

;===Other functions and full code here

CapsLock::Suspend Off
CapsLock Up::Suspend On

This made it much faster and smoother.