AutoHotkey Community

It is currently May 27th, 2012, 8:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: January 23rd, 2012, 9:38 am 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
Code:
Wrap(tag) {
    OldClipboard := Clipboard
    Clipboard := ""
    sleep, 10
    send, ^c
    sleep, 10
    if (Clipboard = "") {
      Clipboard := OldClipboard
      return
    }
    Clipboard := "[" tag "]" . Clipboard . "[/" tag "]"
    send, ^v
    Clipboard := OldClipboard
}

_________________
Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2012, 11:29 am 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Thank you Odlanir, it works great now!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 5:21 am 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
One last small thing: could someone please fix it?
In the final version of the script:
Code:
GroupAdd, Browsers, ahk_class MozillaWindowClass
GroupAdd, Browsers, ahk_class Chrome_WidgetWin_0
GroupAdd, Browsers, ahk_class IEFrame
GroupAdd, Browsers, ahk_class OperaWindowClass

#IfWinActive ahk_group browsers
!sc030::Wrap("b")       ; Alt+B
!sc016::Wrap("u")       ; Alt+U
!sc017::Wrap("i")       ; Alt+I
!sc019::Wrap("img")     ; Alt+P
!sc010::Wrap("quote")   ; Alt+Q
!sc023::Wrap("h")       ; Alt+h
!sc01F::Wrap("s")       ; Alt+s
!sc02D::Wrap("spoiler") ; Alt+x
!Up::Wrap("sup")        ; Alt+Up
!Down::Wrap("sub")      ; Alt+Down

Wrap(tag) {
    OldClipboard := Clipboard
    Clipboard := ""
    sleep, 10
    send, ^c
    sleep, 10
    if (Clipboard = "") {
      Clipboard := OldClipboard
      return
    }
    Clipboard := "[" tag "]" . Clipboard . "[/" tag "]"
    send, ^v
    Clipboard := OldClipboard
}

Hitting the hotkeys - puts selected text into the corresponding tags, but it also loses the selection.
Could you, please, modify the script so, that the inserted part (e.g. selected text inside the tags) becomes selected?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 1:08 pm 
I love those 'one more thing' threads ;-)
If you use IE you might be able to pull it off using com, but otherwise you will have to resort to the FIND feature
(^f)
Code:
Wrap(tag) {
    OldClipboard := Clipboard
    Clipboard := ""
    sleep, 10
    send, ^c
    sleep, 10
    if (Clipboard = "") {
      Clipboard := OldClipboard
      return
    }
    Clipboard := "[" tag "]" . Clipboard . "[/" tag "]"
    send, ^v
    sleep 100
    Send ^f
    Sleep 100
    Send %clipboard% ; see * comment below
    Clipboard := OldClipboard
}


* If you use longs blocks of text I suggest you search for the first few words otherwise it will become very ugly very soon.

Alternative 1: place the caret after the first tag in text OR just before the closing tag? (You can do what with simple down/left commands, again after the first can become quite ugly if you use long texts often).

Alternative 2: place caret in the tag by sending a few lefts after the paste, then send a double or triple click to select all


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 2:08 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
it is completely a bad idea to use find functions.
It opens findbar, it erases last search word in it. It finds the searched phrase, but it doesn't select it. Browser just highlights the found results, but that's not the same as selecting them.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 4:45 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
You can try this:

Code:
Wrap(tag) {

   OldClipboard := Clipboard, open :=   "[" tag "]", close :=   "[/" tag "]"
   Clipboard :=   ""
   sleep, 10
   send, ^c
   sleep, 10
   if   (Clipboard = "")
      return   False, Clipboard := OldClipboard
   Clipboard := open . Clipboard . close
   send, ^v
   Sleep, 10
   Send %   "{LEFT " StrLen(close) "}{SHIFT DOWN}{LEFT " StrLen(Clipboard) - StrLen(open) - StrLen(close) "}{SHIFT UP}"
   return   True, Clipboard := OldClipboard
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 5:01 pm 
iDrug wrote:
Browser just highlights the found results, but that's not the same as selecting them.
Not true for FF anyway, if you close the find the found text is selected. But sorry for trying to be helpful, won't happen again I'm sure.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 5:08 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
sinkfaze For multiline text you must count also the CR-LF:
Code:
   crlf := RegExReplace(clipboard, "`r`n","",count) +""+ count
   Send %   "{LEFT " StrLen(close) "}{SHIFT DOWN}{LEFT " StrLen(Clipboard) - StrLen(open) - StrLen(close) - crlf "}{SHIFT UP}"

_________________
Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 10:52 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Guys, you are awesome!
It now highlights the previously selected text, though a bit slow.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2012, 10:57 pm 
Use SetBatchLines -1 to run the script at maximum speed.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, hyper_, immunity, migz99, sjc1000 and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group