Results 1 to 6 of 6

Thread: I want to make a counter program that i cna run in the background

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    4

    I want to make a counter program that i cna run in the background

    When i press i button i want the counter to go up by one. I already have this code but i need it to run when i'm not on the selected window. Say i'm in chrome or another window. Thank you

    Just in case you want the counter code here it is:

    Public Class Form1
    Dim Counter As Integer

    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    Select Case e.KeyCode
    Case Keys.ControlKey
    Counter += 1
    Case Keys.R
    Counter = 0
    Label2.Text = ""
    TextBox1.Enabled = True
    Button1.Enabled = True
    TextBox1.Show()
    Button1.Show()
    End Select
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Counter
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Label2.Text = TextBox1.Text
    TextBox1.Enabled = False
    Button1.Enabled = False
    TextBox1.Hide()
    Button1.Hide()
    End Sub
    End Class
    Last edited by Shamac01; Nov 25th, 2016 at 01:12 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: I want to make a counter program that i cna run in the background

    For future reference, please use formatting tags when posting code snippets for readability.
    vb.net Code:
    1. Public Class Form1
    2.     Dim Counter As Integer
    3.  
    4.     Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    5.         Select Case e.KeyCode
    6.             Case Keys.ControlKey
    7.                 Counter += 1
    8.             Case Keys.R
    9.                 Counter = 0
    10.                 Label2.Text = ""
    11.                 TextBox1.Enabled = True
    12.                 Button1.Enabled = True
    13.                 TextBox1.Show()
    14.                 Button1.Show()
    15.         End Select
    16.     End Sub
    17.  
    18.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    19.         Label1.Text = Counter
    20.     End Sub
    21.  
    22.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    23.         Label2.Text = TextBox1.Text
    24.         TextBox1.Enabled = False
    25.         Button1.Enabled = False
    26.         TextBox1.Hide()
    27.         Button1.Hide()
    28.     End Sub
    29. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Lively Member
    Join Date
    Jan 2016
    Posts
    87

    Re: I want to make a counter program that i cna run in the background

    Hi!
    Should this app work as a key logger?

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    4

    Re: I want to make a counter program that i cna run in the background

    no just a simple counter so say if i press control the counter goes up by 1

  5. #5
    Lively Member
    Join Date
    Jan 2016
    Posts
    87

    Re: I want to make a counter program that i cna run in the background

    When i press i button i want the counter to go up by one. I already have this code but i need it to run when i'm not on the selected window. Say i'm in chrome or another window. Thank you
    As I figured out from this text, you wish does your app should run in the background until you are in another app.
    But, if you press lets say the "T" button or whatever else your app in the background should increase a counter.

    Actually that is something like a keyloger.

    The keyloger is in the background of your app in which you are working and collects data.
    Now, what the keyloger a does it is up to you...

    Here is a simple code what I already tested and is working:
    use a Timer enabled and the interval should be 100
    Whenever you press the "w" the value in the labelbox increases.
    Whenever you press the "s" the value in the labelbox decreases.
    No matter in which app are you.

    Code:
    Public Class Form1
        Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Dim MyKey1 As Boolean
            Dim MyKey2 As Boolean
            Dim a As Integer = 0
            MyKey1 = GetAsyncKeyState(Keys.W)
            MyKey2 = GetAsyncKeyState(Keys.S)
    
            If MyKey1 = True Then
                a = Label1.Text + 1
                Label1.Text = a
            End If
    
            If MyKey2 = True Then
                a = Label1.Text - 1
                Label1.Text = a
            End If
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Label1.Text = 0
        End Sub
    End Class
    I hope this snippet of code will help you go forward.
    But don't forget to give a reputation if I helped in anyway.

    My best regards.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    4

    Re: I want to make a counter program that i cna run in the background

    Thank you my dude. Much Appreciated

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width