Skip to content

Instantly share code, notes, and snippets.

@JanChec
Last active April 30, 2023 14:45
Show Gist options
  • Save JanChec/65adafd1f566ae4f40bc02899747d1eb to your computer and use it in GitHub Desktop.
Save JanChec/65adafd1f566ae4f40bc02899747d1eb to your computer and use it in GitHub Desktop.
Windows 11 - AutoHotkey - Shallow copy on selection and shallow paste on middle click
; This is a shallow clipboard version of:
; https://www.autohotkey.com/board/topic/44064-copy-on-select-implementation/#entry274436
cos_mousedrag_treshold := 20 ; pixels
cos_copied_text := ""
#IfWinNotActive ahk_class ConsoleWindowClass
~lButton::
MouseGetPos, cos_mousedrag_x, cos_mousedrag_y
keywait lbutton
mousegetpos, cos_mousedrag_x2, cos_mousedrag_y2
if (abs(cos_mousedrag_x2 - cos_mousedrag_x) > cos_mousedrag_treshold
or abs(cos_mousedrag_y2 - cos_mousedrag_y) > cos_mousedrag_treshold)
{
wingetclass cos_class, A
if (cos_class == "Emacs")
sendinput !w
else {
previous_clipboard := clipboard
sendinput ^c
sleep 50 ; wait for copied text to be stored in clipboard
cos_copied_text := clipboard
clipboard := previous_clipboard
}
}
return
~mbutton::
WinGetClass cos_class, A
if (cos_class == "Emacs")
SendInput ^y
else {
previous_clipboard := clipboard
clipboard := cos_copied_text ; copy stored text to clipboard
sleep 50 ; I'm not sure if this is necessary
SendInput ^v
clipboard := previous_clipboard
}
return
#IfWinNotActive
;; clipx
^mbutton::
sendinput ^+{insert}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment