Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Cool] Clipboard - Copy/Cut Logger !
#1
*THIS IS NOT ILLEGAL*

WARNING: It was first coded for LeetCoders contest. It's not advertising.

Source:
Code:
'\\   Author:    Soul Collector
'\\   Language:  VB .NET aka. Visual Basic 2008
'\\   Contact: soulcoll3ctor@live.com
'\\   Comments: Please, if you use it. Give credits to Me(Soul Collector), thanks.

Public Class Form1
    Dim Stored As String
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Stored = My.Computer.Clipboard.GetText = False Then
            If lblNumb.Text = 0 = False Then
                lblNumb.Text = lblNumb.Text + 1
                txtBoard.Text = txtBoard.Text & vbNewLine & vbNewLine & "Log " & lblNumb.Text & " - " & My.Computer.Clipboard.GetText
                Stored = My.Computer.Clipboard.GetText
            Else
                lblNumb.Text = lblNumb.Text + 1
                txtBoard.Text = txtBoard.Text & "Log " & lblNumb.Text & " - " & My.Computer.Clipboard.GetText
                Stored = My.Computer.Clipboard.GetText
            End If
        Else
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub
End Class

Screenshot:
[Image: 29ly1dw.png]

Video example:
[yt]http://www.youtube.com/watch?v=TjkhiwTX1aY[/yt]

Download Project & Binary:
http://www.multiupload.com/RAG6M587VI

P.S. If you use it in your program, please give proper credits to me(Soul Collector), thanks.
[/font]
Reply
#2
kinda cool, thanks for source Big Grin
[Image: Navineous.gif]
Reply
#3
It seems to be very useful Smile Thanks for the source code and a tutorial video GREAT! Thumbsup Simple and great project Smile
[Image: theblackmarketwqryt.jpg]
Reply
#4
Hmm what does this basically do?..
Is it like it records what you copied? If so then i <3 u. I always copy double things and then i have to go back to the page and copy it again =.=
Thanks ^^
Reply
#5
its very useful SOurce COde

Thanks Smile
Reply
#6
(04-08-2010, 05:41 AM)Teh Wrote: Hmm what does this basically do?..
Is it like it records what you copied? If so then i <3 u. I always copy double things and then i have to go back to the page and copy it again =.=
Thanks ^^
Similarly I do this!
Pretty useful Smile
I doubt ill use the source, but thanks for the video; Makes it so much easier to understand what it is than just a wall of text that most people post Pirate
Reply
#7
Oh wow this is really nice...Thanks for the post dude.
Reply
#8
There's another way to do it. You are using the technique of polling - checking every x seconds if the clipboard changed. In general the alternative to polling is to use events. .Net doesn't expose any clipboard events, but you can use the Windows Api.

You register your form as a Clipboard viewer. There are a bunch of viewers, and they have to co-operate to maintain the list of viewers that windows uses to know where to send messages. The viewers are in a Chain. If a viewer leaves the chain, then windows tells the first window in the chain which one left. The first window has to tell the next window, and so on down the chain until it reaches the hole.

It's not quite as bad as it sounds. Here I wrap the api and raise an event when the clipboard changes...

Code:
Option Strict On
Option Explicit On

Imports System.Runtime.InteropServices

Public Class Form1

    ' We'll raise this event using the windows api...
    Private Event ClipboardChanged()
    Private Const WM_CHANGECBCHAIN As Integer = &H30D
    Private Const WM_DRAWCLIPBOARD As Integer = &H308
    Private hNextWindow As IntPtr

    Private Declare Auto Function SetClipboardViewer Lib "user32" (ByVal hWndViewer As IntPtr) As IntPtr
    Private Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    Private Declare Auto Function ChangeClipboardChain Lib "user32" (ByVal hWndRemove As IntPtr, ByVal hWndNewNext As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean

    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        ' Register with windows as a clipboard viewer.
        hNextWindow = SetClipboardViewer(Me.Handle)
    End Sub

    ' (This would be better off inside the Dispose method in Form1.designer.vb)
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        ' Remove ourselves from the clipboard chain.
        ChangeClipboardChain(Me.Handle, hNextWindow)
    End Sub

    ' Once registered as a clipboard viewer windows will send us messages.
    ' We can intercept windows messages sent to the form in this sub.
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_CHANGECBCHAIN
                ' We are responsible for telling the next window in the clipboard viewer chain when the chain has changed.
                ' wParam is the handle of the window that has been removed from the chain.
                ' lParam is the handle of the next window or IntPtr.Zero if there is no next window.
                If m.WParam = hNextWindow Then
                    ' The next window is the one being removed. We now should use lParam as next window
                    hNextWindow = m.LParam
                Else
                    If m.LParam <> IntPtr.Zero Then
                        ' Send the message to the next window.
                        SendMessage(m.LParam, m.Msg, m.WParam, m.LParam)
                    End If
                End If
            Case WM_DRAWCLIPBOARD
                ' The clipboard changed!
                RaiseEvent ClipboardChanged()
        End Select
        MyBase.WndProc(m)
    End Sub

    ' Do stuff in here.
    Private Sub Form1_ClipboardChanged() Handles Me.ClipboardChanged
        If My.Computer.Clipboard.ContainsText Then
            Me.TextBox1.Text = My.Computer.Clipboard.GetText
        End If
    End Sub

End Class

The advantage of using events is that you get instant notification when it changes, and your app doesn't use as many resources.
Reply
#9
Nice tut.Thanks for posting.
[Image: 20r9vh4.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Source] Proxy Grabber [Cool] Hell Guardian 12 8,470 04-07-2015, 11:46 AM
Last Post: polas
  Cool Example - Enumerating IEnumerable of Nullable Types AceInfinity 4 1,891 08-05-2012, 09:24 PM
Last Post: AceInfinity
  Get Cool Custom Buttons [VB.NET] [Source] Vorfin 30 10,577 04-02-2011, 01:49 PM
Last Post: h4yr0

Forum Jump:


Users browsing this thread: 1 Guest(s)