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 x5

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
psych0pat



Joined: 28 Apr 2008
Posts: 12

PostPosted: Tue Apr 29, 2008 12:06 am    Post subject: ClipBoard x5 Reply with quote

I've had this idea for a long time now and finally decided to carry it out. There are many many bugs, as this is the first attempt. I'm sure you'll figure out what I'm trying to do just by checking it out and looking at the code. Any help, tips, tricks, ideas, or support will be greatly appreciated. Please and thank you. Smile

Code:
Gui, Add, GroupBox, x0 y0 w100 h100, Slot 1
Gui, Add, GroupBox, x100 y0 w100 h100, Slot 2
Gui, Add, GroupBox, x200 y0 w100 h100, Slot 3
Gui, Add, GroupBox, x300 y0 w100 h100, Slot 4
Gui, Add, GroupBox, x400 y0 w100 h100, Slot 5
Gui, Add, Button, x0 y120 w100 gClear1, Clear
Gui, Add, Button, x100 y120 w100 gClear2, Clear
Gui, Add, Button, x200 y120 w100 gClear3, Clear
Gui, Add, Button, x300 y120 w100 gClear4, Clear
Gui, Add, Button, x400 y120 w100 gClear5, Clear
Gui +AlwaysOnTop
Gui, Show, xCenter y0, CBx5

Clipboard =
OnClipBoardChange:
If Slot1=
{
Slot1 := ClipboardAll
Gui, Add, Picture, x1 y20 w98 h80 gPaste1, %ClipBoard%
GuiControl, Move, Static6, x1
}
Else if Slot2=
{
Slot2 := ClipboardAll
Gui, Add, Picture, x101 y20 w98 h80 gPaste2, %ClipBoard%
Gui, Add, Picture, x101 y101, Marker.gif

}
Else if Slot3=
{
Slot3 := ClipboardAll
Gui, Add, Picture, x201 y20 w98 h80 gPaste3, %ClipBoard%
GuiControl, Move, Static6, x201
}
Else if Slot4=
{
Slot4 := ClipboardAll
Gui, Add, Picture, x301 y20 w98 h80 gPaste4, %ClipBoard%
GuiControl, Move, Static6, x301
}
Else if Slot5=
{
Slot5 := ClipboardAll
Gui, Add, Picture, x401 y20 w98 h80 gPaste5, %ClipBoard%
GuiControl, Move, Static6, x401
}
Else if Slot5 !=
{
Gui, 2:Add, Text,, All slots already occupied.
Gui, 2:Add, Text,, Please empty a slot.
Gui, 2:Show
}
CBChange:
Return

Clear1:
MsgBox, 4, Clear?, Are you sure you want to clear slot 1?
IfMsgBox, Yes
{
Slot1 =
GuiControl, , Static4,
Return
}
Else IfMsgBox, No
{
Return
}

Clear2:
MsgBox, 4, Clear?, Are you sure you want to clear slot 2?
IfMsgBox, Yes
{
Slot2 =
GuiControl, , Static5,
Return
}
Else IfMsgBox, No
{
Return
}

Clear3:
MsgBox, 4, Clear?, Are you sure you want to clear slot 3?
IfMsgBox, Yes
{
Slot3 =
GuiControl, , Static6,
Return
}
Else IfMsgBox, No
{
Return
}

Clear4:
MsgBox, 4, Clear?, Are you sure you want to clear slot 4?
IfMsgBox, Yes
{
Slot4 =
GuiControl, , Static7,
Return
}
Else IfMsgBox, No
{
Return
}

Clear5:
MsgBox, 4, Clear?, Are you sure you want to clear slot 5?
IfMsgBox, Yes
{
Slot5 =
GuiControl, , Static8,
Return
}
Else IfMsgBox, No
{
Return
}

Paste1:
ClipBoard = %Slot1%
GuiControl, Move, Static6, x1
Goto, CBChange

Paste2:
ClipBoard = %Slot2%
Gui, Add, Picture, x101 y101, Marker.gif
Goto, CBChange

Paste3:
ClipBoard = %Slot3%
Gui, Add, Picture, x201 y101, Marker.gif
Goto, CBChange

Paste4:
ClipBoard = %Slot4%
Gui, Add, Picture, x301 y101, Marker.gif
Goto, CBChange

Paste5:
ClipBoard = %Slot5%
Gui, Add, Picture, x401 y101, Marker.gif
Goto, CBChange
Back to top
View user's profile Send private message AIM Address
Icarus



Joined: 24 Nov 2005
Posts: 507

PostPosted: Mon May 05, 2008 12:40 pm    Post subject: Reply with quote

Two comments I have for you:

One, when you have multiple items that do the same thing, use arrays, or loops to create them / process them

Two, The Gui Add Picture command is intended to add a picture file. The fact that it seemed to work for you when you copied text, is that AHK was looking for an image this name, and when it did not find it, it placed the "filename" which was the contents of your clipboard.

Three, you attempted to "add picture" on every copy. What I believe you intended to do, is to MODIFY the contents of the "picture" and not add another one.

So, I have modified your code to accommodate the above comments. Note that this code works on text snippets and not pictures. I am just providing the code to demonstrate my comments.

Code:

#SingleInstance Force
SetWorkingDir %A_ScriptDir%


; Configuration
SLOT_COUNT = 5      ; Set the number of slots

; Empty the clipboard
Clipboard =

; Build the GUI
X := 10
Loop %SLOT_COUNT% {
  Gui Add, GroupBox, x%X% y10 w112 h120 section, Slot %A_Index%
  Gui Add, Text, xp+10 yp+18 w90 h90 vContent%A_IndeX% gPaste
  Gui Add, Button, xs y+14 w112 vBtnClear%A_Index% gClear, Clear
  X += 120
}
Gui +AlwaysOnTop
Gui, Show, y100, ClipMaster

Return

GuiEscape:
GuiClose:
  ExitApp
Return

; Capture clipboard changes, and copy them to the slots
OnClipBoardChange:
  If( Clipboard = "" )
    Return
   
  TheSlot := 0
  Loop %SLOT_COUNT% {
    If( Content%A_Index% = "" ) {
      Content%A_Index% := Clipboard     
      TheSlot := A_Index
      Break
    }
  }
 
  If( TheSlot = 0 )
    MsgBox Please clear a slot.
  Else
    GuiControl,,Content%TheSlot%, % Content%TheSlot%

Return

; Clears a slot
Clear:
  StringReplace ButtonIndex, A_GuiControl, BtnClear
  Content%ButtonIndex% := ""
  GuiControl,,Content%ButtonIndex%, % ""
Return

; Paste the content of the slot, when it is clicked
Paste:
  StringReplace ButtonIndex, A_GuiControl, Content
  If( Content%ButtonIndex% = "" )
    Return
 
  SendInput % "!{Tab} " . Content%ButtonIndex%
Return


Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
psych0pat



Joined: 28 Apr 2008
Posts: 12

PostPosted: Thu May 08, 2008 10:22 pm    Post subject: Thanks Reply with quote

Thank you so much for your help Icarus! Very Happy In case you didn't notice, I'm clearly a noob.

And not to be a smart a** or anything, but that was three comments Razz . lol.
Back to top
View user's profile Send private message AIM Address
Mkbailey755



Joined: 20 Aug 2007
Posts: 178

PostPosted: Thu May 08, 2008 10:30 pm    Post subject: Reply with quote

A noob wouldnt be able to right that
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 507

PostPosted: Thu May 08, 2008 10:38 pm    Post subject: Re: Thanks Reply with quote

psych0pat wrote:
Thank you so much for your help Icarus! Very Happy In case you didn't notice, I'm clearly a noob.

And not to be a smart a** or anything, but that was three comments Razz . lol.


We are all noobs at something, sometime right? Smile
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
psych0pat



Joined: 28 Apr 2008
Posts: 12

PostPosted: Sat May 10, 2008 4:58 pm    Post subject: Reply with quote

Very true.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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