Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Capturing a series of keystrokes at any time

Capturing a series of keystrokes at any time

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcom
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jsampsonPC
    wrote on last edited by
    #1

    My question is rather simple. We all have played computer games, or other console-based games, where at any given moment you can type in "thereisnotry", or something similar and it activates a new feature, be it a class method giving you maximum health, or whatever. How exactly can that be done in VB.NET? Line, at any time if I type in "magic string" I can catch that event (is that an event?) and handle it...

    Jonathan Sampson www.SampsonResume.com

    L D 2 Replies Last reply
    0
    • J jsampsonPC

      My question is rather simple. We all have played computer games, or other console-based games, where at any given moment you can type in "thereisnotry", or something similar and it activates a new feature, be it a class method giving you maximum health, or whatever. How exactly can that be done in VB.NET? Line, at any time if I type in "magic string" I can catch that event (is that an event?) and handle it...

      Jonathan Sampson www.SampsonResume.com

      L Offline
      L Offline
      Leah_Garrett
      wrote on last edited by
      #2

      What type of application is it? In a Windows Forms application you could look at using the KeyPress event. You will, though, need to handle the event for each control on the form

      Private m\_strCapturedString As String = ""
      
      Private Sub TextBox1\_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
          If System.Char.IsControl(e.KeyChar) Then
              Exit Sub
          End If
      
          m\_strCapturedString += e.KeyChar
      
          If m\_strCapturedString.Length = 10 Then
              MessageBox.Show(m\_strCapturedString)
          End If
      End Sub
      
      Private Sub Button1\_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
          If System.Char.IsControl(e.KeyChar) Then
              Exit Sub
          End If
      
          m\_strCapturedString += e.KeyChar
      
          If m\_strCapturedString.Length = 10 Then
              MessageBox.Show(m\_strCapturedString)
          End If
      End Sub
      
      1 Reply Last reply
      0
      • J jsampsonPC

        My question is rather simple. We all have played computer games, or other console-based games, where at any given moment you can type in "thereisnotry", or something similar and it activates a new feature, be it a class method giving you maximum health, or whatever. How exactly can that be done in VB.NET? Line, at any time if I type in "magic string" I can catch that event (is that an event?) and handle it...

        Jonathan Sampson www.SampsonResume.com

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You don't have to handle the keydown event of every control. You just have to do it in the Form's KeyDown event. But, in order for it to work, you have to turn on (True) the Form's KeyPreview property. There is no event for the typing of a string of characters, only one keystroke. Your Form's KeyPress event handler code then has to keep track of the last "x" number of keys that were hit and compare them to the string you want as your "cheat" string.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups