Recieving keyboard input OUTSIDE of the application?

Discussion in 'Programming & Scripting' started by gunfreak010, Feb 1, 2009 with 2 replies and 182 views.

  1. gunfreak010

    gunfreak010 Enthusiast

    Messages:
    21
    Ratings:
    0
    Alright, im creating a spammer thingy, and there have been problems with it. The first problem I experienced was when I accidentally put the spam into the spammed text. I cured that with textBox1.readonly = true;, but I have since ran into another problem - Some windows overload, and when they do that, there is NO WAY to stop it :x3:


    To cure that, I would need to intercept keystrokes outside of the application. Basically, I want f4 to start a timer, and f5 to stop it, all from outside of the application, in a seperate window. I tried the keypreview stuff off of MSDN, but that only worked whilst I was inside of the same form as my spammer, aka - useless.

    How would I do this? :x3:
     
  2. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
  3. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Seeing as how I don't have C# installed on this computer, I'll give you a simple method of accomplishing this in VB.

    Start off with two timers, set timer1 to enabled on load (you can do that in the properties panel). Put the spammer stuff (I'm guessing sendkeys and whatnot) on timer2, and the hotkeys will be on timer1.

    Code:
       Private Declare Function GetAsyncKeyState Lib "user32" (ByVal Key As Long) As Integer
    
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If GetAsyncKeyState(System.Windows.Forms.Keys.F4) Then
    Timer2.Enabled = True
    ElseIf GetAsyncKeyState(System.Windows.Forms.Keys.F5) Then
    Timer2.Enabled = False
    End If
    End Sub