Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ClipPad – keypad for private clipboards


  • Please log in to reply
2 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
If you have a vertical taskbar, there is some unused space in it. The Windows clock, for example, takes up 3 rows, while one row is sufficient (see here). Or, usually there is room next to the Start button. You can even cover it partially. The following script places a keypad over the top 2 clock lines. You can assign arbitrary actions to the buttons, I chose a set of configurable private clipboards. If anything (picture, formatted text, movie clip, etc.) is selected in an application and you right click one of the buttons, a menu pops up. There you can choose to copy the selection to the button (Update), delete the currently saved content, save all the contents to disk, show all the data assigned to buttons (in WordPad) or exit the application. When the script starts, it loads all the saved clipboards back.

If you hover the mouse on a button already containing data, its text content is shown as tooltip. (Images cannot be shown.) If you click a button, its content is pasted into the last active application, at the insertion point.

There are also keyboard shortcuts. Pressing in a row [, ], and the name of the button pastes its data where you are typing. [, ] and ? opens the show in WordPad.
#NoTrayIcon                         ; Tray icon is unnecessary
Process Priority,,High              ; for speed
SetWinDelay 0                       ; for speed

;----- edit here for best look -----

ButtonW = 18                        ; Width of the buttons
ButtonH = 24                        ; Heights
OffsX   = -1                        ; Leftmost button position
Font    = Arial                     ; For button text
FontAttr= Bold S10

Idx = abcdefghijklmnopqrst          ; Button labels
Idx2   := StrLen(Idx)//2 + 1

KpX     = 0                         ; KeyPad size
KpY     = 1117
KpH    := 2*ButtonH
KpW    := (Idx2-1)*ButtonW + OffsX

;----- code starts here -----

SaveDir = %A_ScriptDir%\SavedClips  ; where clips are saved to/loaded from
IfNotExist %SaveDir%
{
   FileCreateDir %SaveDir%          ; Run at the very first time
   Loop Parse, Idx                  ; Create save-directory and empty clips
   {
      FileAppend,,%SaveDir%\B%A_LoopField%
      FileAppend,,%SaveDir%\A%A_LoopField%
   }
}

SetTimer ClearTip                   ; Remove tooltip if mouse is outside
OnMessage(0x200,"Hover")            ; 0x200 = WM_MOUSEMOVE used instead of WM_MOUSEHOVER

Menu RClickMenu,Add,&Update,Update
Menu RClickMenu,Add,&Delete,Delete  ; Right click menu items
Menu RClickMenu,Add,Sho&w,  Show
Menu RClickMenu,Add,&Save,  Save
Menu RClickMenu,Add,&Exit,  6GuiClose

Gui 6:-Caption +AlwaysOnTop ToolWindow ; No title, no taskbar icon
Gui 6:Margin, 0,0
Gui 6:font, %FontAttr%, %Font%
Gui 6:Add, Button,x%OffsX% y0 h0 w0 ; Dummy button, changed by docking
Loop Parse, Idx,                    ; Read ClipBoards and ClipBoardAlls
{
   FileRead CB%A_LoopField%,   %SaveDir%\B%A_LoopField%
   FileRead CA%A_LoopField%,*c %SaveDir%\A%A_LoopField%
   xy = x+0
   IfEqual A_Index,%Idx2%, SetEnv xy,x%OffsX% y+0 ; for the second row of buttons
   Gui 6:Add, Button, %xy% w%ButtonW% h%ButtonH% g6Button, %A_LoopField%
}
Gui 6:Show, x%KpX% y%KpY% h%KpH% w%KpW%, KeyPad6 ; to be put over the taskbar
WinGet KPID, ID, A
Process Exist                       ; Dock to taskbar (PID -> ErrorLevel)
WinGet hw_gui, ID, ahk_pid %ErrorLevel%
hw_tray := DllCall( "FindWindowEx", "uint",0, "uint",0, "str","Shell_TrayWnd", "uint",0 )
DllCall( "SetParent", "uint", hw_gui, "uint", hw_tray )

Return

;----- HotStrings -----

:*B0?:[]::                          ; no end char, OK inside another word, no backspace
   Input
   Input key, V L1, {BACKSPACE}{Left}{Right}{Up}{Down}{PgUp}{PgDown}{Home}{End}{Enter}{Tab}{Esc}
   If key = ?
   {
      Send {BS 3}
      GoTo Show
   }
   StringReplace x, Idx, %key%, %key%, UseErrorLevel
   If ! ErrorLevel
      Return                        ; If key is not a button name
   If StrLen(CA%key%) = 0
   {
      Send {BS 3}
      Return
   }
   ClipBoard =
   ClipBoard := CA%key%             ; Get saved ClipBoardAll
   ClipWait 3                       ; Wait up to 3 seconds
   Send {BS 3}^v                    ; Remove [], Paste to last active window
Return

;----- Subroutines, Functions -----

Show:
   Run WordPad
   WinWaitActive Document - WordPad
   BlockInput On
   Loop Parse, Idx
   {
      If StrLen(CA%A_LoopField%) = 0
         Continue
      ClipBoard =
      ClipBoard := CA%A_LoopField%
      ClipWait 3
      Send [ClipBoard %A_LoopField%]:{Enter}^v`n`n
   }
   BlockInput Off
Return

6Button:                            ; Click on a button
   If StrLen(CA%A_GuiControl%) = 0
      Return
   ClipBoard =
   ClipBoard := CA%A_GuiControl%    ; Get saved ClipBoardAll
   ClipWait 3                       ; Wait up to 3 seconds
   Send !{TAB}^v                    ; Paste to last active window
Return

6GuiContextMenu:                    ; at right click:
   GC = %A_GuiControl%              ; Remember which button was clicked
   Menu RClickMenu, Show            ; Show context menu
Return

Update:                             ; Update clip
   ClipBoard =
   Send !{TAB}^c                    ; Copy from last active window
   ClipWait 2
   CB%GC% = %ClipBoard%             ; ClipBoard is for ToolTip only
   CA%GC% = %ClipBoardAll%          ; ClipBoardAll saved for later paste back
Return

Delete:                             ; Remove clip content
   CB%GC% =
   CA%GC% =
Return

Save:                               ; Save all clips on disk
   Loop Parse, Idx
   {
      FileDelete %SaveDir%\B%A_LoopField%
      FileAppend % CB%A_LoopField%, %SaveDir%\B%A_LoopField%
      FileDelete %SaveDir%\A%A_LoopField%
      FileAppend % CA%A_LoopField%, %SaveDir%\A%A_LoopField%
   }
Return

6GuiClose:                          ; Exit, Save beforehand?
   MsgBox 35, Save? ,Save ClipBoards before exit?
   IfMsgBox Cancel                  ; Cancel: no exit
      Return
   IfMsgBox Yes                     ; Save: do it
      GoSub Save
ExitApp                             ; Terminate

ClearTip:                           ; If outside of GUI
   MouseGetPos,,,ID
   If (ID = KPID or KPtip = )
      Return
   KPtip =                          ; KeyPad tip removed
   ToolTip
Return

Hover()                             ; Called when the mouse hovers GUI
{
   Global KPtip
   KPtip = 1                        ; KeyPad tip is shown
   StringLeft tip, CB%A_GuiControl%, 40
   If (StrLen(CA%A_GuiControl%) > 0 and tip = "")
      tip = <image>
   ToolTip %tip%                    ; Show the saved clipboard
}
I used ideas of Skrommel (AutoClip) and Shimanov (dock GUI to taskbar).

  • Guests
  • Last active:
  • Joined: --
Nothing shows up when I run this script... It creates the dir for saved clips, though, but nothing shows up in windows bar or anywhere..

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You have to edit the position values, especially KpY, the vertical location of the keypad buttons. The value 1117 is for my 1920x1200 pixel monitor, taskbar on the left. You could write it as an expression: KpY := A_ScreenHeight - 2*ButtonH – 2, or something. I have my taskbar clock/calendar underneath, which pushes the buttons up.