AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 22nd, 2012, 4:58 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
the following script:
Code:
!sc030:: Send, ^{sc02E}[b]^{sc02F}[/b] ; Alt+B

puts selected text into bbcode bold tags:
Code:
[b][/b]

but it works so, that:
1. it copies the selected text first, so if you had something in clipboard before script worked - that something will be lost.
How to evade that?
2. it then requires hitting CTRL+Z (Undo) 4 times, instead of 1.
How to make it require just one undo action to undo putting selected text into the tags?

p.s.: how to make this script work only in windows with classes MozillaWindowClass, Chrome_WidgetWin_0 or IEFrame?


Last edited by iDrug on January 24th, 2012, 5:27 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 5:12 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
I use this to put tags. It preserve clipboard contents.
Code:
~^F5::
   OldClipboard := Clipboard
   send, ^c
   ClipWait, 1
   Menu, dsc, Add, Bold, mymenu
   Menu, dsc, Add, Italic, mymenu
   Menu, dsc, Add, Quote, mymenu
   Menu, dsc, Add, Code, mymenu
   Menu, dsc, Show
   send, ^v
   Clipboard := OldClipboard
return
mymenu:
   sleep 100
   IF (A_ThisMenuItem = "Bold")
      Clipboard := "[b]" . Clipboard . "[/b]"
   IF (A_ThisMenuItem = "Italic")
      Clipboard := "[i]" . Clipboard . "[/i]"
   IF (A_ThisMenuItem = "Quote")
      Clipboard := "[quote]" . Clipboard . "[/quote]"
   IF (A_ThisMenuItem = "Code")
      Clipboard := "[code]" . Clipboard . "[/code]"
Return

_________________
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 22nd, 2012, 5:27 pm 
Odlanir,
your code works perfectly, but it is not efficient. Build menu only once in auto-execute section, and after that, just show it on hotkey press.
Code:
Menu, dsc, Add, Bold, mymenu
Menu, dsc, Add, Italic, mymenu
Menu, dsc, Add, Quote, mymenu
Menu, dsc, Add, Code, mymenu
Return

F5::
   OldClipboard := Clipboard
   send, ^c
   ClipWait, 1
   Menu, dsc, Show
   send, ^v
   Clipboard := OldClipboard
return
mymenu:
   sleep 100
   IF (A_ThisMenuItem = "Bold")
      Clipboard := "[b]" . Clipboard . "[/b]"
   IF (A_ThisMenuItem = "Italic")
      Clipboard := "[i]" . Clipboard . "[/i]"
   IF (A_ThisMenuItem = "Quote")
      Clipboard := "[quote]" . Clipboard . "[/quote]"
   IF (A_ThisMenuItem = "Code")
      Clipboard := "[code]" . Clipboard . "[/code]"
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 5:42 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Odlanir wrote:
I use this to put tags. It preserve clipboard contents.

Thanks, but I don't need any menus, the purpose is to fasten the process of bbcoding on forums + without the use of mouse, with just keyboard (well, I didn't test your script, maybe it's possible to navigate in that menu using keyboard too, I just don't like the whole idea of menus.

so my request from the 1st post is still actual for me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 5:46 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
iDrug Just a bit of imagination.
Code:
~^F5::
   OldClipboard := Clipboard
   send, ^c
   ClipWait, 1
   Clipboard := "[b]" . Clipboard . "[/b]"
   send, ^v
   Clipboard := OldClipboard
return

Guest Thanks. I'll follow your suggestion.

_________________
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 22nd, 2012, 6:02 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
does not work: it replaces the selected text with "cv" and that's all.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:09 pm 
Replace clipwait with Sleep, 100 or so and try again.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:18 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Anonymous wrote:
Replace clipwait with Sleep, 100 or so and try again.

Thank you, now it works.
Could you please tell me is there a way to optimize the code?
Code:
~!sc030::
   OldClipboard := Clipboard
   send, ^c
   Sleep, 10
   Clipboard := "[b]" . Clipboard . "[/b]"
   send, ^v
   Clipboard := OldClipboard
return
~!sc016::
   OldClipboard := Clipboard
   send, ^c
   Sleep, 10
   Clipboard := "[u]" . Clipboard . "[/u]"
   send, ^v
   Clipboard := OldClipboard
return
~!sc017::
   OldClipboard := Clipboard
   send, ^c
   Sleep, 10
   Clipboard := "[i]" . Clipboard . "[/i]"
   send, ^v
   Clipboard := OldClipboard
return

As you can see, I use 3 hotkeys and the actions differ just quite a bit.

+ this problem is still actual for me:
How to make this script work only in windows with classes MozillaWindowClass, Chrome_WidgetWin_0 or IEFrame?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:24 pm 
Code:
GroupAdd, Browsers, ahk_class MozillaWindowClass
GroupAdd, Browsers, ahk_class Chrome_WidgetWin_0
GroupAdd, Browsers, ahk_class IEFrame

#IfWinActive ahk_group browsers
~!b::Wrap("b")
~!c::Wrap("u")
~!i::Wrap("i")
#IfWinActive

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



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:24 pm 
Sending Ctrl+smth doesn't work when non standard (English) keyboard layout is active. Workaround for this is to use virtual codes (VK) or scan codes (SC) instead. Use:
Code:
Send ^{vk43}        ; instead of Send ^c
Send ^{vk56}        ; instead of Send ^v
Send ^{vk58}        ; instead of Send ^x
Send ^{vk5A}        ; instead of Send ^z

EDIT: I'm late a little but I think it's still actual.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:27 pm 
^x (cut) is Shift+Del, +{Del}
^c (Copy) is Ctrl+Ins, ^{Ins}
^v (Paste) is Shift+Ins, +{Ins}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:35 pm 
:shock:
I didn't know that. Thank you, Guest


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:39 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Anonymous wrote:
Code:
GroupAdd, Browsers, ahk_class MozillaWindowClass
GroupAdd, Browsers, ahk_class Chrome_WidgetWin_0
GroupAdd, Browsers, ahk_class IEFrame

#IfWinActive ahk_group browsers
~!b::Wrap("b")
~!c::Wrap("u")
~!i::Wrap("i")
#IfWinActive

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


YOU ARE AWESOME!
Thanks a lot!

Gogo wrote:
Sending Ctrl+smth doesn't work when non standard (English) keyboard layout is active. Workaround for this is to use virtual codes (VK) or scan codes (SC) instead. Use:
Code:
Send ^{vk43}        ; instead of Send ^c
Send ^{vk56}        ; instead of Send ^v
Send ^{vk58}        ; instead of Send ^x
Send ^{vk5A}        ; instead of Send ^z

EDIT: I'm late a little but I think it's still actual.

Not late at all! It's an actual problem for me, as I'm using non-eng keyboard layout pretty often.


Everyone,
Thank you!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 6:45 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
Gogo wrote:
:shock:
I didn't know that. Thank you, Guest

Than it might be another surprise for you, try hitting this hotkey in windows:
LAlt+LShift+PrintScreen
and choose "yes".
Looks especially awesome on Win7 8)


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

Joined: October 13th, 2009, 11:56 am
Posts: 102
Actually the script acts even when no text is selected.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, hyper_, immunity, migz99, sjc1000 and 65 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