DP-formatting-right-handed-01
Jump to navigation
Jump to search
Place everything below into the .AHK of your choice. This assumes you have installed AutoHotKey.
Then double click on the file name to activate the key mapping.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #SingleInstance Force ;following is to help Distributed Proofreader Formatters ;Generally, ; you click and drag some text that needs markup (or double or triple click to highlight) ; press a letter while the mouse button is still down ; markup is inserted. ; ;It is smart enough that if you ; double click a word and your browser includes a trailing space in the highlighting, the space will not be included. ; triple click a line and your browser includes the trailing end of line character, the end of line character will not be included. ; overshoot your click and drag to include a leading or trailing space, those spaces are not included. ; ;Maps top row of letter keys QWERT to top row of flags on screen (i,B,Sc,g,f) ;Acknowledged this would be incredibly frustrating for people who mouse with their left hand. ;Acknowledged you might like to us something mnemonic like "i" for italics, etc. This will require a lot more hand movement so not recommended. ;Acknowledged you might find reaching to the top row is uncomfortable and would prefer mapping keys to ASDF rather than QWER ;It's each to change by editing below ;========= Column Marker =========================== ~LButton & `:: rc := flagwrap("``","``") ; double up accent because it is the escape and needs to be escaped return ; This ends the hotkey. The code below this point will not get triggered. ;========= italic and Bold =========================== ~LButton & G:: rc := flagwrap("<i><b>","</b></i>") return ;========= Italics =========================== ~LButton & Q:: rc := flagwrap("<i>","</i>") return ;====== BOLD ======================================= ~LButton & W:: rc := flagwrap("<b>","</b>") return ;======== Small Cap ===================================== ~LButton & E:: rc := flagwrap("<sc>","</sc>") return ;======== G e s p e r r t ===================================== ~LButton & R:: rc := flagwrap("<g>","</g>") return ;======== Antiqua/Fraktur ===================================== ;One project had many words/phrases that were both Italics and Gesperrt so this special case was added. ~LButton & T:: rc := flagwrap("<f>","</f>") return ;========= No Wrap ================================================= ;This is an awkward reach on the keyboard when operating with only your left hand ~LButton & 8:: ;Use 8 as hotkey because * is on it rc := flagwrap("/*`n","`n*/") return ;=========Block Quote================================================= ~LButton & 3:: ;Use 3 as hotkey because # is on it rc := flagwrap("/#`n","`n#/") return ;========= Insert Double Space ================================================= ;A lot of markup wants an even number of spaces. Click and hold mouse while tapping spacebar to get two at a time so you always have an even number. ~LButton & Space:: ;Insert two spaces at current location. Common for poetry indentation SendInput, {Space}{Space} return ;========= Unwrap Line ================================================= ;A nice helper if you need to unwrap a lot of lines. ;Click and hold mouse at end of line and press delete. ;Much more convenient then clicking at the end of a line, pressing delete, then pressing space. ~LButton & Delete:: ;Insert space and delete newline. Use by clicking and holding at end of line of poetry SendInput, {Space}{Delete} return ;=========Foot note ================================================= ;Footnote added as an option. ; It is not as smart as the markup button on the screen as it will let you use inappropriate foot note anchor like "*" ~LButton & F:: lflag := "[Footnote" rflag := "]" Clipboard := ; clear out the clipboard so the wait two statements below will work SendInput, {Ctrl down}c{Ctrl up} ; Copies the selected text. ClipWait ; ; clean up mess because windows does LF and CR so a paste adds extra line breaks Clipboard := StrReplace(Clipboard, "`r`n", "`n") ;Wrap the text in the desired flag FootArray := StrSplit(Clipboard, " ", ,2) ; split into two parts: footnote number which is first word and footnote text which is the rest Clipboard := "[Footnote " FootArray[1] ": " FootArray[2] "]" ; wrap text in footnote flags and reassemble ; clean up when double click grabs trailing blank Clipboard := StrReplace(Clipboard, " " rflag, rflag " ") Snapshot := Clipboard ; clean up when triple click grabs trailing line break Clipboard := StrReplace(Clipboard, "`n" rflag, rflag "`n" ) ;msgBox, , Swiss, %Snapshot% `n %Clipboard%, ; Type the modified input string back in, then move cursor up a line and to left margin. Sometimes it goes somewhere annoying. SendInput, {Ctrl down}v{Ctrl up} SendInput, {Home}{Up} return ;================================================== flagwrap(lflag,rflag) ; subroutine that will wrap whatever text string is selected with whatever tags you like { ;It would be great if someone figured out how to get rid of the workaround on the next line. ; Things sometimes, irregularly screw up if you don't pop up the message box and wait a second. ; The ClipWait should make it work but debug has not borne fruit yet. ;msgbox ,, flagwrap, %lflag% %rflag% ,1 ;1 makes it wait one second, needed or generally does not work Clipboard := ; clear out the clipboard so the wait two statements below will work SendInput, {Ctrl down}c{Ctrl up} ; Copies the selected text. ClipWait , 2 ; ; clean up mess because Windows does LF and CR so a paste adds extra line breaks ; If using a Linux or MAC it might not be needed and could make a mess if left here. Clipboard := StrReplace(Clipboard, "`r`n", "`n") ;If it is small caps, then make it title type caps ;This was needed for one particular project and is left here to be re-activated if needed again. ;if (%lflag% = "<sc>") ; StringUpper, Clipboard, Clipboard, T ;Wrap the text in the desired flag Clipboard := lflag Clipboard rflag ; clean up when double click grabs trailing blank or user swipes a little too far right including the trailing space Clipboard := StrReplace(Clipboard, " " rflag, rflag " ") ; clean up when user swipes a little too far left including the leading space Clipboard := StrReplace(Clipboard, lflag " ", " " lflag) ; clean up when triple click grabs trailing line break ; Beware if using Linux or MAC. Some adjustment might be needed. Clipboard := StrReplace(Clipboard, "`n" rflag, rflag "`n" ) ;msgBox,,Swiss2,%StringOut%,2 ; Type the modified input string back in, then move cursor up a line and to left margin. ; Sometimes it goes somewhere annoying. However leaving at the end of the markup is frequently annoying. SendInput, {Ctrl down}v{Ctrl up} ;SendInput, {Home}{Up} ;msgBox,,Swiss2,%StringOut%,2 return 0 }