Page 1 of 1

Sending rich-text input, independent of program hotkeys?

Posted: 22 Apr 2019, 06:57
by Klaus2
Is it possible to attach rich text formatting to a string sent to software?

Usecase: In Physics, vectors are commonly written as bold, upright characters. For instance, inserting the vector r in MS Office equations corresponds to sending ^b^ir^b^i*. However, this is somewhat brittle:
  • It has to assume, that the current font is "italic, non-bold". As a consequence it fails e.g. in headings, or when italics have been disabled in the equation for some reason (e.g. because the vector as preceded by an upright keyword).
  • I have to use German office on some devices, where the hotkeys don't match.
It would therefore be preferable to be able to send explicitly formatted text.

In similar circumstances, I am often using the clipboard variable, and sending the text using ^v. I am not aware of any method to achieve rich-text formatting in this context.


------------------------------------------
* Just sending the plain keysequence doesn't work actually; It will result in weird behavior inside nested parantheses. Instead I sprinkled some Sleep invocations into the process.

Re: Sending rich-text input, independent of program hotkeys?

Posted: 22 Apr 2019, 07:27
by list

Re: Sending rich-text input, independent of program hotkeys?

Posted: 22 Apr 2019, 11:40
by Klaus2
list wrote:
22 Apr 2019, 07:27
1. Tutorial various methods https://www.autohotkey.com/boards/viewtopic.php?f=7&t=8977 (check method 4)
2. Lintalist https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3378 :-)
WinClip.Clear(), WinClip.SetHTML() seems to be the closest match, as it allows to generate the pasted content on the fly.

Sadly, it doesn't work reliably. Most of the time,

Code: Select all

WinClip.Clear()
WinClip.SetHTML("<b>foo</b>")
just leaves the clipboard empty.

Also, pasting at the end of an equation puts the cursor outside the equation, so my main usecase won't work with the clipboard apparently :/

Re: Sending rich-text input, independent of program hotkeys?

Posted: 22 Apr 2019, 14:22
by list
Insert some Sleeps between the WinClip commands and before the paste. You can of course move your cursor (which is actually named the caret) by sending left/right arrow keys after the paste of course. WinClip works well for me.

Perhaps you could look into COM for MS Word or write a Word macro (record just what you type) and see what code you can use from that.