Guys i need help with this code with the code regarding using the getasynckeystate for ctrl + c and ctrl+ v or copy and paste..How will I do that in this code? For example when i type in notepad it should also do in the richtextbox with this code it work but when it comes to copy and paste word in notepad it does not works and the richtextbox is empty. Help please:)

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For i = 1 To 255
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                RichTextBox1.Text = RichTextBox1.Text + Chr(i)

            End If
        Next i

        If GetAsyncKeyState(32) <> 0 Then
            RichTextBox1.Text = RichTextBox1.Text + ""

        End If
    End Sub

Recommended Answers

All 9 Replies

GetAsyncKeyState doesn't check clipboard, that's for sure.
You monitor the clipboard contents if you want and use GetAsyncKeyState to see if the data got pasted using Ctrl+V, but I don't see how you could tell if the data got pasted by clicking the paste icon or the Edit/Paste from menus.

What are you building? Is there no other way to get what you want?

I was creating a simple application in vb.net that when I type any word in notepad or even in microsoft word that word that you type should also see in richtextbox. That code do is accept only from a to z and also spacebar but the problem is when i try to copy a word and paste it in a notepad in the richtextbox it does not show the word that I copy and paste using the ctrl+c and ctrl+v. Note: notepad is just a sample even microsoft word it work and also when i run the program with textbox the word that i type in textbox it also type in the richtextbox.. How could the copy paste word when i paste it, it should also see in richtextbox? what ever i paste should also see in richtextbox.

Like I've said if the user pastes the data from the menus or the icons or by right-clicking and selecting paste from there, you won't be able to. In order to handle this you have to go app specific or control the mouse and even then there is a ton of paste methods that will be left unhandled, so for out let's say it's out of scope.

If you want to check when pasting (copying won't matter to you), check with getasynckeystate if Ctrl + V has been pressed. If it has been pressed use Clipboard.GetText.

Edit: You are not making a keylogger, are you?

oh yes similar with key logger i forgot to mention that similar to key logger..

You are on your own.

You are on your own.

\

Do you know how to do that? those copy and paste word because using that code above it always output for a copy and paste word like a box.

Dim iData As IDataObject = Clipboard.GetDataObject()
        If iData.GetDataPresent(DataFormats.Text) Then
            RichTextBox1.SelectedText = CType(iData.GetData(DataFormats.Text), String)
        End If

this is what i did when you mention about the clipboard but it use button in order to paste the word in richtextbox1 but when i use timer event it continues to paste the word. What was the problem of using timer but for those timer key it works only in this code for clipboard does not work properly. thanks

I'm sorry arjen, but I'm not going to help you build a keylogger or anything similar.
Each person has a right to his/hers privacy and I am not going to help you violate that.

ok i understand :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.