Skip to content

Commit

Permalink
refactor: replace Send with SendInput for improved reliability in key…
Browse files Browse the repository at this point in the history
… input operations.

refactor: remove `SendMode("Input")` setting as all Send was replaced by SendInput
  • Loading branch information
rcmdnk committed Sep 28, 2024
1 parent 9a5b57a commit 9fca214
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 123 deletions.
12 changes: 6 additions & 6 deletions lib/bind/vim_command.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ w::Vim.State.SetMode("Command_w")
q::Vim.State.SetMode("Command_q")
h::
{
Send("{F1}")
SendInput("{F1}")
Vim.State.SetMode("Vim_Normal")
}

#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w"))
Enter::
{
Send("^s")
SendInput("^s")
Vim.State.SetMode("Vim_Normal")
}

q::
{
Send("^s")
Send("!{F4}")
SendInput("^s")
SendInput("!{F4}")
Vim.State.SetMode("Insert")
}

Space::
{
Send("!fa")
SendInput("!fa")
Vim.State.SetMode("Insert")
}

#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q"))
Enter::
{
Send("!{F4}")
SendInput("!{F4}")
Vim.State.SetMode("Insert")
}

Expand Down
10 changes: 5 additions & 5 deletions lib/bind/vim_enter_insert.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ i::Vim.State.SetMode("Insert")

+i::
{
Send("{Home}")
SendInput("{Home}")
Vim.State.SetMode("Insert")
}

a::
{
if(! Vim.CheckChr("`n")){
Send("{Right}")
SendInput("{Right}")
}
Vim.State.SetMode("Insert")
}

+a::
{
Send("{End}")
SendInput("{End}")
Vim.State.SetMode("Insert")
}

o::
{
Send("{End}{Enter}")
SendInput("{End}{Enter}")
Vim.State.SetMode("Insert")
}

+o::
{
Send("{Home}{Enter}{Left}")
SendInput("{Home}{Enter}{Left}")
Vim.State.SetMode("Insert")
}

Expand Down
28 changes: 14 additions & 14 deletions lib/bind/vim_normal.ahk
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal"))
; Undo/Redo
u::Send("^z")
^r::Send("^y")
u::SendInput("^z")
^r::SendInput("^y")

; Combine lines
+j:: Send("{End}{Space}{Delete}")
+j:: SendInput("{End}{Space}{Delete}")

; Change case
~::
{
ClipSaved := ClipboardAll()
A_Clipboard := ""
Send("+{Right}^x")
SendInput("+{Right}^x")
ClipWait(1)
if(isLower(A_Clipboard)){
A_Clipboard := StrUpper(A_Clipboard)
}else if(isUpper(A_Clipboard)){
A_Clipboard := StrLower(A_Clipboard)
}
Send("^v")
SendInput("^v")
A_Clipboard := ClipSaved
}

+z::Vim.State.SetMode("Z")
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z"))
+z::
{
Send("^s")
Send("!{F4}")
SendInput("^s")
SendInput("!{F4}")
Vim.State.SetMode("Vim_Normal")
}

+q::
{
Send("!{F4}")
SendInput("!{F4}")
Vim.State.SetMode("Vim_Normal")
}

; period
.::Send("+^{Right}{BS}^v")
.::SendInput("+^{Right}{BS}^v")

; Q-dir
#HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal")
; For Q-dir, ^X mapping does not work, use !X instead.
; ^X does not work to be sent, too, use Down/Up
; switch to left top (1), right top (2), left bottom (3), right bottom (4)
!u::Send("{LControl Down}{1 Down}{1 Up}{LControl Up}")
!i::Send("{LControl Down}{2 Down}{2 Up}{LControl Up}")
!j::Send("{LControl Down}{3 Down}{3 Up}{LControl Up}")
!k::Send("{LControl Down}{4 Down}{4 Up}{LControl Up}")
!u::SendInput("{LControl Down}{1 Down}{1 Up}{LControl Up}")
!i::SendInput("{LControl Down}{2 Down}{2 Up}{LControl Up}")
!j::SendInput("{LControl Down}{3 Down}{3 Up}{LControl Up}")
!k::SendInput("{LControl Down}{4 Down}{4 Up}{LControl Up}")
; Ctrl+q, menu Quick-links
'::Send("{LControl Down}{q Down}{q Up}{LControl Up}")
'::SendInput("{LControl Down}{q Down}{q Up}{LControl Up}")
; Keep the e key in Normal mode, use the right button and then press the refresh (e) function, do nothing, return to the e key directly
~e::
{}
Expand Down
8 changes: 4 additions & 4 deletions lib/bind/vim_replace.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ r::Vim.State.SetMode("r_once")
~>::
~Space::
{
Send("{Del}")
SendInput("{Del}")
Vim.State.SetMode("Vim_Normal")
}

::: ; ":" can't be used with "~"?
{
Send("{:}{Del}")
SendInput("{:}{Del}")
Vim.State.SetMode("Vim_Normal")
}

Expand Down Expand Up @@ -200,12 +200,12 @@ r::Vim.State.SetMode("r_once")
~>::
~Space::
{
Send("{Del}")
SendInput("{Del}")
}

:::
{
Send("{:}{Del}")
SendInput("{:}{Del}")
}

#HotIf
12 changes: 6 additions & 6 deletions lib/bind/vim_search.ahk
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal"))
/::
{
Send("^f")
SendInput("^f")
Vim.State.SetMode("Insert")
}

*::
{
ClipSaved := ClipboardAll()
A_Clipboard := ""
Send("^{Left}+^{Right}^c")
SendInput("^{Left}+^{Right}^c")
ClipWait(1)
Send("^f")
Send("^v!f")
SendInput("^f")
SendInput("^v!f")
A_Clipboard := ClipSaved
Vim.State.SetMode("Insert")
}

n::Send("{F3}")
+n::Send("+{F3}")
n::SendInput("{F3}")
+n::SendInput("+{F3}")

#HotIf
22 changes: 11 additions & 11 deletions lib/bind/vim_visual.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
v::Vim.State.SetMode("Vim_VisualChar")
^v::
{
Send("^b")
SendInput("^b")
Vim.State.SetMode("Vim_VisualChar")
}

+v::
{
Vim.State.SetMode("Vim_VisualLineFirst")
Send("{Home}+{Down}")
SendInput("{Home}+{Down}")
}

#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual"))
Expand All @@ -20,10 +20,10 @@ v::Vim.State.SetMode("Vim_Normal")
y::
{
A_Clipboard := ""
Send("^c")
Send("{Right}")
SendInput("^c")
SendInput("{Right}")
if WinActive("ahk_group VimCursorSameAfterSelect"){
Send("{Left}")
SendInput("{Left}")
}
ClipWait(1)
if(Vim.State.StrIsInCurrentVimMode("Line")){
Expand All @@ -36,7 +36,7 @@ y::
d::
{
A_Clipboard := ""
Send("^x")
SendInput("^x")
ClipWait(1)
if(Vim.State.StrIsInCurrentVimMode("Line")){
Vim.State.SetMode("Vim_Normal", 0, 0, 1)
Expand All @@ -48,7 +48,7 @@ d::
x::
{
A_Clipboard := ""
Send("^x")
SendInput("^x")
ClipWait(1)
if(Vim.State.StrIsInCurrentVimMode("Line")){
Vim.State.SetMode("Vim_Normal", 0, 0, 1)
Expand All @@ -60,7 +60,7 @@ x::
c::
{
A_Clipboard := ""
Send("^x")
SendInput("^x")
ClipWait(1)
if(Vim.State.StrIsInCurrentVimMode("Line")){
Vim.State.SetMode("Insert", 0, 0, 1)
Expand All @@ -73,10 +73,10 @@ c::
{
ClipSaved := ClipboardAll()
A_Clipboard := ""
Send("^c")
SendInput("^c")
ClipWait(1)
Send("^f")
Send("^v!f")
SendInput("^f")
SendInput("^v!f")
A_Clipboard := ClipSaved
Vim.State.SetMode("Vim_Normal")
}
Expand Down
Loading

0 comments on commit 9fca214

Please sign in to comment.