johnp
Junior

Karma: +1/-0
Offline
Posts: 24
|
 |
« on: May 18, 2008, 05:34:42 PM » |
|
I sometimes want to highlight some text in a topic and am too lazy to get into edit mode and type in all those '%' characters.
Here is a little AutoHotKey hack to highlight a text area without entering the editor. To use it, select a piece of text in a topic while in view mode, then type <Alt>-h . (If you already have Alt-h mapped to something, change the 'h' in the first line of the script to the character of your choice).
This could obviously be tweaked to do underlining, italics, etc. The ambitious could probably implement an entire WYSIWYG editor this way, and never enter edit mode again... :twisted:
- John
-----------cut here------------------------------ !h::
; CT - highlight the selected text. Send !e Send ^c ClipWait 1, 1 Send `%`%class=highlite`%`% Send %clipboard% Send `%`%`%`% Send !e Return
|
|
|
|
|
Logged
|
- John
|
|
|
johnp
Junior

Karma: +1/-0
Offline
Posts: 24
|
 |
« Reply #1 on: May 18, 2008, 05:45:22 PM » |
|
I just learned something about AutoHotKey, which is that 'Sendinput' is much faster than 'Send', so here is an improved version of the above script:
-----------cut here------------------------------ !h::
; CT - highlight the selected text. Send !e Send ^c ClipWait 1, 1 Send `%`%class=highlite`%`% Sendinput, %clipboard% Send `%`%`%`% Send !e Return
|
|
|
|
|
Logged
|
- John
|
|
|
honwahp
Junior

Karma: +0/-0
Offline
Posts: 32
|
 |
« Reply #2 on: February 06, 2010, 03:18:18 AM » |
|
Thanks John for sharing this autohotkey script. It is really helpful . However, it works fine only with English words and doesn't work with Chinese words. With Chinese words, the words that I highlighted turned into question marks(with the highlight) after I pressed Alt-h. It would be really nice if this problem can be solved. I am also curious to know if there is a method to change the highlight color to one that I choose myself. 
|
|
|
|
« Last Edit: February 06, 2010, 03:23:10 AM by honwahp »
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #3 on: February 06, 2010, 05:51:45 AM » |
|
I don't know whether this will work with Chinese (as I have no way of testing it), but try this: F4:: ; or whatever shortkey you want clipboard = Send, ^x ClipWait clipBoard = %clipboard% clipboard = `%`%class=highlite`%`%%clipboard%`%`%`%`% send, ^v return
Manfred P.S. I find that "Send" works more reliably than "SendInput" or "SendPlay" on Windows 7 (64 bit).
|
|
|
|
« Last Edit: February 06, 2010, 05:54:41 AM by kuehnm »
|
Logged
|
|
|
|
honwahp
Junior

Karma: +0/-0
Offline
Posts: 32
|
 |
« Reply #4 on: February 06, 2010, 06:32:48 AM » |
|
Hi Manfred thanks for responding. But sorry to tell you that when I ran your code(and pressed the hotkey), nothing happened and the code didn't even work with English words. 
|
|
|
|
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #5 on: February 06, 2010, 07:13:46 AM » |
|
Don't understand.
It works for me ... What Windows version are you running?
If you want to play, you might want to try "SendInput" for "Send". You might also want to substitute "^c" for "^x", as some keyboards (and, if I remember correctly ConnectedText also) have a problem with "^x"
Finally, do you use "F4" for anything else?
Manfred
|
|
|
|
« Last Edit: February 06, 2010, 07:24:57 AM by kuehnm »
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #6 on: February 06, 2010, 07:29:26 AM » |
|
Oh, and you have to be in the editor for it to work. (I should have looked at the top of the Subject ...!) This also works from view mode (at least for me). F4:: ; highlight selected text Send, !e clipboard = Send, ^x ClipWait clipBoard = %clipboard% clipboard = `%`%class=highlite`%`%%clipboard%`%`%`%`% send, ^v Send, !e return
Manfred
|
|
|
|
« Last Edit: February 06, 2010, 07:38:55 AM by kuehnm »
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #7 on: February 06, 2010, 07:53:26 AM » |
|
The last script won't work with Chinese either. Trying to highlight a Chinese passage from Code Beamer also gives only question marks. Doing just a little more research, I think it has to do with the version of AHK you (and I) run. It can't do unicode. This one, the unicode version, might give you better results: http://www.autohotkey.com/forum/topic50485.html&highlight=unicodeI say "might," as I have not tried it. Manfred
|
|
|
|
« Last Edit: February 06, 2010, 07:58:03 AM by kuehnm »
|
Logged
|
|
|
|
honwahp
Junior

Karma: +0/-0
Offline
Posts: 32
|
 |
« Reply #8 on: February 06, 2010, 07:59:24 AM » |
|
Thanks! Manfred. I'll definitely take a look when I have the time.
|
|
|
|
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #9 on: February 06, 2010, 10:28:16 AM » |
|
This works for Chinese text as well (without a new installation of AhK)—at least for me: F4:: Clipboard = Send !e Send ^c ClipWait Transform UC, Unicode ; Save Unicode text Transform Clipboard, Unicode, %UC% Send, `%`%class=highlite`%`% Send, ^v Send, `%`%`%`% Sleep 50 Send, !e Return
Let me know whether it works for you. Best wishes, Manfred P.S.: Look at "Transform" in the AhK help file. Should also work for other languages.
|
|
|
|
« Last Edit: February 06, 2010, 01:50:20 PM by kuehnm »
|
Logged
|
|
|
|
honwahp
Junior

Karma: +0/-0
Offline
Posts: 32
|
 |
« Reply #10 on: February 06, 2010, 12:07:16 PM » |
|
Yes, Manfred. It does work. But about one out of five times there was this error message that said " Cannot open clipboard", which is a little bit annoying. Anyway, thanks very much for your help  Howard
|
|
|
|
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #11 on: February 06, 2010, 12:20:06 PM » |
|
This seems to be a general problem, not one having to do with Ahk. See, for instance http://stackoverflow.com/questions/1859102/how-can-i-fix-cannot-open-clipboard-access-denied-errorsPerhaps adding Sleep, 50 between Clipboard = and Send ^c will help. Manfred P.S.: A Google search for "cannot open clipboard" will bring up many discussions; none of the ones I have seen help a great deal. Just repeat the action after a little while.
|
|
|
|
« Last Edit: February 06, 2010, 12:26:36 PM by kuehnm »
|
Logged
|
|
|
|
honwahp
Junior

Karma: +0/-0
Offline
Posts: 32
|
 |
« Reply #12 on: February 06, 2010, 12:43:37 PM » |
|
Perhaps adding Sleep, 50 between Clipboard = and Send ^c will help.
This really solved the problem! I experimented about thirty times and no more error messages!
|
|
|
|
« Last Edit: February 06, 2010, 10:06:43 PM by honwahp »
|
Logged
|
|
|
|
kuehnm
Beta testers
Master
  
Karma: +14/-0
Offline
Posts: 229
|
 |
« Reply #13 on: February 07, 2010, 02:04:33 PM » |
|
I am glad it works. Manfred
|
|
|
|
|
Logged
|
|
|
|
johnp
Junior

Karma: +1/-0
Offline
Posts: 24
|
 |
« Reply #14 on: February 15, 2010, 01:56:07 PM » |
|
I am also curious to know if there is a method to change the highlight color to one that I choose myself.  In your CSS file, look for the lines: .highlite { background-color:#ffff66; } And change the color to your preferred one. - John
|
|
|
|
|
Logged
|
- John
|
|
|
|