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. C#
  4. keyboard event listener

keyboard event listener

Scheduled Pinned Locked Moved C#
5 Posts 2 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.
  • H Offline
    H Offline
    hazzem elrefai
    wrote on last edited by
    #1

    i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance

    H H 2 Replies Last reply
    0
    • H hazzem elrefai

      i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance

      H Offline
      H Offline
      hazzem elrefai
      wrote on last edited by
      #2

      i recieve nothing..... thnx

      1 Reply Last reply
      0
      • H hazzem elrefai

        i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        If another Control has the focus (and it most likely does), you won't receive keyboard events. You have to set Form.KeyPreview to true. Then you should have better results.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        H 1 Reply Last reply
        0
        • H Heath Stewart

          If another Control has the focus (and it most likely does), you won't receive keyboard events. You have to set Form.KeyPreview to true. Then you should have better results.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          H Offline
          H Offline
          hazzem elrefai
          wrote on last edited by
          #4

          but i wanna listen to more than one key like "ctrl+h" or like this

          H 1 Reply Last reply
          0
          • H hazzem elrefai

            but i wanna listen to more than one key like "ctrl+h" or like this

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            As far as text in your console app go, you can use the Console.In properties (a TextReader) to grab typeable characters like "h". When you get input like this, call the GetKeyState method (after P/Invoking it, of course) to determine whether or not a modifier key is pressed.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            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