AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Clipboard manager via Mouse menu

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Thu Jun 10, 2004 8:49 pm    Post subject: Clipboard manager via Mouse menu Reply with quote

Hi, I've used Rajats mouse menu script to make this clipboard manager. The items in the menu are arrange in alphabetical order.

1) Select The text that you use want to paste somewhere else later. Than press Ctrl+Alt+C. Give it a title when the inputbox appears. Select as many sections of text as you want.

2) Go to where you wan to paste the text and hold down the middle mouse button for a second. A menu will appear with all of the titles you enter earlier.

3) Left click on one of the titles and the text you copied earlier and gave that title will be copied into the open window.

4) To delete an item, Hold down F2 and Click the menu item.

The Script requires the latest version of Autohotkey.

Code:



MenuTitle = =========

;Delay after which the menu is shown
UMDelay = 20

SetFormat, float, 0.0
SetBatchLines, 10ms

;Creates ini file if it doesn't exist
ifnotexist, %a_scriptdir%\ToolTipMenu.ini, fileappend, [MenuItem]`nName=, %a_scriptdir%\ToolTipMenu.ini

Exit


;<<<<Reads Menu names from ini file>>>>

Mbutton::

          IniRead, name, ToolTipMenu.ini, MenuItem, Name

        Loop, parse, name, `,
        {
          if name =
   {
               break
   }
 
          MenuItem%a_index% = %A_LoopField%
        }

;<<<<Sets menu delay>>>>

        HowLong = 0
        Loop
        {
                HowLong ++
                Sleep, 10
                GetKeyState, Mbutton, Mbutton, P

              If Mbutton = U
   {
   Break
   }
        }

        If HowLong < %UMDelay%
   {
   Return
   }

        Menu = %MenuTitle%

;<<<<Creates Menu Items to be displayed>>>>

        Loop
        {
              If MenuItem%a_index% =
   {
   Break
   }

                MenuItems ++
                StringTrimLeft, MenuText, MenuItem%a_index%, 0
                Menu = %Menu%`n%MenuText%
        }

;<<<<Displays Menu>>>>

        ToolTip, %Menu%
        WinActivate, %MenuTitle%

Return

;<<<<Turns Menu off >>>>

~LButton::

GetKeyState, state, F2

         IfWinNotActive, %MenuTitle%
         {
                 ToolTip
                 Return
         }

;<<<<Gets Mouse position and position of menu items>>>>

         MouseGetPos, mX, mY
         ToolTip
        mY -= 3                ;space after which first line starts
        mY /= 13        ;space taken by each line
        IfLess, mY, 1, Return
        IfGreater, mY, %MenuItems%, Return


;<<<<Finds name of text file>>>>

j=1

Loop, parse, name, `,
{

if j = %mY%
{
docname=%A_LoopField%
break
}

j++

}

;<<<<If key is held down, item is deleted>>>>

if state =D
{


FileDelete, %docname%.txt


IniRead, name, ToolTipMenu.ini, MenuItem, name, (blank)

j=1

Loop, parse, name, `,
{
j++
}


two=2

if j=%two%
{
StringReplace, newname, name, %docname%,
}
else
{

i=%j%
i-=1


if mY=%i%
{
StringReplace, newname, name, `,%docname%,
}
else
{
StringReplace, newname, name, %docname%`,,
}

}

iniWrite, %newname%, ToolTipMenu.ini, MenuItem, name

reload

EXIT

}

;<<<<Reads from text file and send  each line to window>>>>

sleep, 100

setkeydelay, 0

Loop, read, %docname%.txt
{

Loop, parse, A_LoopReadLine
{
send, %A_LoopField%
}

}

Return

;<<<<Copies selected text to file>>>>

^!c::

clipboard=

Winactivate

send, ^c

ClipWait, 3
if ErrorLevel <> 0
{
   MsgBox, The attempt to copy text onto the clipboard failed.
   return
}

copied=%clipboard%

AutoTrim, On

StringLeft, default, copied, 25

StringReplace, default, default, `r, %A_Space%,all
StringReplace, default, default, `n, %A_Space%,all

sleep, 100

InputBox, menu, Menu Title, Please enter a menu title, , 400, 150, , , , , %default%

menu=%menu%

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

j=1

Loop, parse, name, `,
{

if menu = %A_LoopField%
{
msgbox, Error`, The same menu name cannot be specified more than once
EXIT
}

j++

}

FileAppend, %copied%`n, %menu%.txt

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

if name=
{
IniWrite, %menu%, ToolTipMenu.ini, MenuItem, Name
EXIT
}

IniWrite, %menu%`,%name%, ToolTipMenu.ini, MenuItem, Name

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

Sort, name, D,

StringLeft, firstletter, name, 1

comma=`,

if firstletter = %comma%
{
StringTrimLeft, name, name, 1
}

IniWrite, %name%, ToolTipMenu.ini, MenuItem, Name



Thanks to Rajat for the menu and giving me the idea of how to make the menu dynamic. Very Happy

edit:
just made a couple changes to the script to make it more reliable


Last edited by Jon on Fri Jun 11, 2004 2:50 am; edited 11 times in total
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Thu Jun 10, 2004 9:24 pm    Post subject: Reply with quote

yep! the script is great!

may i make a few suggestions...


this will make key sending use steroids!
setkeydelay, 0


maybe it'd be better to take first 10-15 chars of the clipboard text as the title instead of asking for a title.... or maybe this is just my preference.. Smile


how about this line:
ifnotexist, %a_scriptdir%\ToolTipMenu.ini, fileappend, [MenuItem]`nName=, %a_scriptdir%\ToolTipMenu.ini

Quote:
Thanks to Rajat for the menu and giving me the idea of how to make the menu dynamic.


i'm glad that it worked (and thanx for letting me know the same)... it seemed theoritically correct but i'd not tried it.
_________________
Back to top
View user's profile Send private message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Thu Jun 10, 2004 10:44 pm    Post subject: Reply with quote

Thanks Very Happy

Quote:

this will make key sending use steroids!
setkeydelay, 0


Thanks, It copies alot faster now

Quote:

maybe it'd be better to take first 10-15 chars of the clipboard text as the title instead of asking for a title.... or maybe this is just my preference..


Good Idea, Just added it in, Better that having to manually enter a title each time.

This was definetely one of the more challenging scripts I've written.

Thanks alot for your suggestions and help. Very Happy
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Jun 11, 2004 1:18 pm    Post subject: Reply with quote

That's really nice the way you've set it up to provide a default name for the copied text. And the idea of holding down F2 to delete an item is ingenious and convenient. Also, the way you've made the clipboard text persistent across reboots and restarts of the script is a great feature!

I'm planning to add scripts such as this one to the Script Showcase on the web site.
Back to top
View user's profile Send private message Send e-mail
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Fri Jun 11, 2004 4:50 pm    Post subject: Reply with quote

Thanks Chris Very Happy
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group