AutoHotkey Community

It is currently May 26th, 2012, 11:15 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 14th, 2009, 10:55 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
I'd like to write a script which wraps selected text in quotes or parens.

Here's what I have

Code:
#W::
inputbox, mycharactertype, Character?,Character? `Left of `(`{`[`"`<`,
wrap(myCharacterType) ; call function below
return
wrap(mycharacterinput)
{
   send, ^x
   sleep,100
   if (mycharacterinput = """)
        ; script won't load this line
        ; have tried " and `" and "`""
   {
      send, `"`" ; I have never actually tried this part, stuck above
   }
   if (mycharacterinput = "`'")
   {
      send, `'`'
   }
   if (mycharacterinput = "`(")
   {
      send, `(`)
   }   
   if (mycharacterinput = "`{")
   {
      send, `{`}
   }
   if (mycharacterinput = "`[")
   {
      send, `[`]
   }
   if (mycharacterinput = "`<")
   {
      send, `<`>
   }
   send, {left}^v{{right}{space} ; end after pasting and moving right
}


It doesn't work and I'm out of ideas.

I think that I have read the manual and searched the forum.

Thanks for the amazing product and huge community.

gunns256


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2009, 11:03 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
A quote is escaped by quote.
Code:
Send ""
Send {{}
Send []

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2009, 11:11 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Another approach is to make a hotkey on the delimiter, as:
Code:
; note ( is on the 8 button on my keyboard
#8::
  clipboard=
  send ^x
  clipwait,1
  send (^v)
return

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2009, 11:18 pm 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
i'm confused between your topic vs description vs script.

if you want to wrap text in quotes, parens etc ...

There is a handy function called Rapidhotkey

Copy or download it and install in your Autohotkey.exe LIB folder

Here are some examples:
just copy any text to the clipboard and then use these scripts.
it wraps the text in whatever special character you choose.
For m ore examples read the Radiohotkey help file in the function script.

Code:
#NoEnv
#Persistent
#SingleInstance
SetTitleMatchMode = 2
#InstallKeybdHook
SendMode, Input

$"::RapidHotkey("{ASC 0034}""{Shift}{ASC 0034}{Shift}{ASC 0034}{left}", 2) ; TESTED tewo(2) taps, single quote (), Three(3) taps quote pair usng Ascii characters to send nonalphanumeric symbols
~'::RapidHotkey("{ASC 0039}{ASC 0039}{left}", 2) ; TESTED usng Ascii characters to send nonalphanumeric symbols
~[::RapidHotkey("[]{Left}", 2) ; TESTED Single(!) tap pastes single bracket Two(2) taps pastes bracket pair
~[::RapidHotkey("[]{Left}""[url=[/url]{left 6}",2, 1)  ; TESTED same as above

if you want something else then restate your requirements

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2009, 1:14 am 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Thanks for 3 very quick responses. I will try them tomorrow morning.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Final Function
PostPosted: November 15th, 2009, 4:11 am 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Here's my finalized hotkey and function to cut text and wrap it the chosen character. I wound up testing for ascii values and sending ascii characters. I am pleased with how it turned out.

Code:
#W:: ; cut text and wrap with selected character
inputbox, mycharactertype, Wrap text with what character?,Wrap text with what character?`n`" or quote2 or 1 `t`t`( or paren or 2 `n`{ or brace or 3 `t`t`[ or brack or 4 `n`' or quote1 or 5 `t`t< or param or 6
wrap(myCharacterType)
return
wrap(mycharacterinput)
{
   send, ^x
   text2paste = %Clipboard% ; to get autotrim
   if (instr(mycharacterinput, chr(34)) or (mycharacterinput = "quote2") or (mycharacterinput = "1")) ; double quote
   {
      send,{asc 0034}{asc 0034}
   }
   else if (instr(mycharacterinput, chr(123)) or (mycharacterinput = "brace") or (mycharacterinput = "3")) ; brace
   {
      send, {asc 0123}{asc 0125}
   }
   else if (instr(mycharacterinput, chr(40)) or (mycharacterinput = "paren") or (mycharacterinput = "2")) ; parentheses
   {
      send, {asc 0040}{asc 0041}
   }
   else if (instr(mycharacterinput, chr(91)) or (mycharacterinput = "brack") or (mycharacterinput = "4")) ; bracket
   {
      send, {asc 0091}{asc 0093}
   }
   else if (instr(mycharacterinput, chr(39)) or (mycharacterinput = "quote1") or (mycharacterinput = "5")) ; single quote
   {
      send, {asc 0039}{asc 0039}
   }
   else if (instr(mycharacterinput, chr(60)) or (mycharacterinput = "param") or (mycharacterinput = "6")) ; gt lt params
   {
      send, {asc 0060}{asc 0062}
   }
   Else
   {
      msgbox,buh
      return
   }
   sendinput, {left}%text2paste%{right}{space}
   return
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cerberus, JSLover, Maestr0, rbrtryn, Tipsy3000 and 67 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