autohotkey - How to wrap currently selected text in `` -
how can write hotkey (which works in editor) wrap selected text in ``
e.g double click "text", becomes selected, pressing key single `` converted
text
here mix of pseudo code , actual code. text within <> i'm not sure of
^<command pressing ` key>:: keywait control <store selected text in memory> sendinput `<stored selected text>' return
your approach pretty already. try this:
$`:: clp_tmp := clipboardall send ^c currently_selected := clipboard stringreplace, currently_selected, currently_selected, `r,, clipboard := clp_tmp sendraw ``%a_space% sendraw %currently_selected% sendraw ``%a_space% return $ needed because otherwise, sendraw `` re-trigger hotkey. built-in variable clipboard / clipboardall contains windows' clipboard. also, don't need keywaits. ahk manages concurring modifiers hotkey triggers itself. suggest using sendraw not treat # win-button, + shift , on.
script inserts new lines between each line if multiple lines selected
weird. when using msgbox, %currently_selected% instead of send command, line breaks displayed correctly... there strange formatting going on, fixed removing carriage returns (cr) (`r) string not change selected text @ all.
the given solution works keyboard german. this might different other keyboard layouts. me, %a_space% in sendraw ``%a_space% (at least in second one) needed, because if state sendraw `` (a literal space character in end), ahk ignore it. put 3 sends in 1 line like
sendraw `` %currently_selected%``%a_space% another solution might be
sendinput ````{bs}%currently_selected%````{bs} or simply
sendraw `%currently_selected%` finally: if wanted make easier, make use of #escapechar command , change delimiter ` \ or sth. similar.
Comments
Post a Comment