hello !
i want to develop the keycounter , i mean i want to get the total no. of key pressed by the user in the specific time , i have a code of keylogger , i can use it to get the text in that time period and after that just get its length , but i dont want to use this . here is a code of VB.net which i found so for on msdn

Private Shared keyPressCount As Long = 0
    Private Shared backspacePressed As Long = 0
    Private Shared returnPressed As Long = 0
    Private Shared escPressed As Long = 0


    Private Sub myKeyCounter(ByVal sender As Object, ByVal ex As KeyPressEventArgs)
        Select Case ex.KeyChar
            ' Counts the backspaces.
            Case ControlChars.Back
                backspacePressed = backspacePressed + 1
                ' Counts the ENTER keys.
            Case ControlChars.Lf
                returnPressed = returnPressed + 1
                ' Counts the ESC keys.  
            Case Convert.ToChar(27)
                escPressed = escPressed + 1
                ' Counts all other keys.
            Case Else
                keyPressCount = keyPressCount + 1
        End Select

        textBox1.Text = backspacePressed & " backspaces pressed" & _
            ControlChars.Lf & ControlChars.Cr & escPressed & _
            " escapes pressed" & ControlChars.CrLf & returnPressed & _
            " returns pressed" & ControlChars.CrLf & keyPressCount & _
            " other keys pressed" & ControlChars.CrLf
        ex.Handled = True
    End Sub 'myKeyCounter

and

    Public Sub New()
        InitializeComponent()

        AddHandler TextBox1.KeyPress, AddressOf myKeyCounter
    End Sub 'New

i get this code from this link Click Here. this code working fine but only when my i am typing on my textbox1 , i want to count all the keys pressed on any part of the screen .
if possible then please help me to solve this issue ,you can help me in C# the code of C# you can find on the above link,
and suggestion will be highly appreciated.

Regards

zrehman809 commented: is there an application (or an "innocuous" keylogger) that could tally how often I press the keys on my console amid a particular time +0

KeyLogger.. Anyways.. Here you go. Tested and works!

Imports System.Runtime.InteropServices
Public Class MyForm
    Public BackKeyIsDown As Boolean
    Public BackKeyDownCount As Integer
    Public EnterKeyIsDown As Boolean
    Public EnterKeyDownCount As Integer
    Public EscKeyIsDown As Boolean
    Public EscKeyDownCount As Integer
    Public OtherKeyIsDown As Boolean
    Public OtherKeyDownCount As Integer

    <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Boolean 'short
    End Function

    Private Sub MyTimer_Tick(sender As Object, e As EventArgs) Handles MyTimer.Tick
        'Back
        If GetAsyncKeyState(Keys.Back) Then 'BackSpace is Down
            BackKeyIsDown = True
        Else
            If BackKeyIsDown Then
                BackKeyIsDown = False
                BackKeyDownCount += 1
                MessageBox.Show("BackSpace: " & BackKeyDownCount)
            End If
        End If
        'Enter
        If GetAsyncKeyState(Keys.Return) Then 'Enter is Down
            EnterKeyIsDown = True
        Else
            If EnterKeyIsDown Then
                EnterKeyIsDown = False
                EnterKeyDownCount += 1
                MessageBox.Show("Enter: " & EnterKeyDownCount)
            End If
        End If
        'Esc
        If GetAsyncKeyState(Keys.Escape) Then 'Esc is Down
            EscKeyIsDown = True
        Else
            If EscKeyIsDown Then
                EscKeyIsDown = False
                EscKeyDownCount += 1
                MessageBox.Show("Esc: " & EscKeyDownCount)
            End If
        End If
        'Other
        'You can't detect 'Other' you have to detect a certain key!
    End Sub
End Class

i want to calculate the total key press , including space enter , backspace function keys etc. i have this code of keylogger , but this code is not working on vs2008 .net framework 4.0 . please how i can make to work.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        On Error Resume Next
        Dim result As Integer
        Dim key As String
        Dim i As Integer
        For i = 2 To 90
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                key = Chr(i)
                If i = 13 Then key = vbNewLine
                Exit For
            End If
        Next i
        If key <> Nothing Then
            If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
                TextBox1.Text &= key
            Else
                TextBox1.Text &= key.ToLower

            End If
        End If
    End Sub

.

Best Regards

Well, this is quite long. But it works! Talk about writing code for people. But it wasn't hard anyways since I made a program to write it for me. :P
Anyways here.

http://www.mediafire.com/?ze2j0tc4h7bj1iu

I would have posted it here, but like I said, it's quite long.

commented: Thanks :) +5

your code worked for me . i just make some changes init according to my requirement. thank you so much ,
Thread is solved.

Regards

No Probs! :D

thanks works fine :)

i want a code to calculate the count each time ctrl+alt+s is pressed in the form of a background app

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.