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. key down in windows forms (C# 2.0) [modified]

key down in windows forms (C# 2.0) [modified]

Scheduled Pinned Locked Moved C#
questioncsharpwinforms
9 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.
  • C Offline
    C Offline
    C Scharbe
    wrote on last edited by
    #1

    i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006

    I D 2 Replies Last reply
    0
    • C C Scharbe

      i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006

      I Offline
      I Offline
      Ilia Blank
      wrote on last edited by
      #2

      Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?

      C I 2 Replies Last reply
      0
      • I Ilia Blank

        Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?

        C Offline
        C Offline
        C Scharbe
        wrote on last edited by
        #3

        any key down not specially to a control in the form

        I 1 Reply Last reply
        0
        • C C Scharbe

          any key down not specially to a control in the form

          I Offline
          I Offline
          Ilia Blank
          wrote on last edited by
          #4

          You have to install windows hook procedure to intercept all keyboard events. Look at “How can I use 'Hooks' in .NET” article at following link http://72.14.203.104/search?q=cache:NUhXDPTnLJgJ:www.syncfusion.com/FAQ/WindowsForms/FAQ\_c70c.aspx+"DllImport"+SetWindowsHookEx+WH\_KEYBOARD+C%23&hl=en&gl=ca&ct=clnk&cd=1

          1 Reply Last reply
          0
          • C C Scharbe

            i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006

            D Offline
            D Offline
            darkelv
            wrote on last edited by
            #5

            Try setting the form's keypreview to true, then catch the key down of the form.

            I C 2 Replies Last reply
            0
            • I Ilia Blank

              Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?

              I Offline
              I Offline
              Ilia Blank
              wrote on last edited by
              #6

              You can read about windows hooks in .Net here http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/[^] Use WH_KEYBOARD when installing the hook procedure with SetWindowsHookEx Use following code to detect key down in your hook static readonly int WM_KEYDOWN = 256, public Int32 KeyboardProc(int code, Int32 wParam, Int32 lParam) { if ((Int32)wParam == (Int32)WM_KEYDOWN ) { // do processing } // do not forget to call next hook !!!!!!!!!!!! // CallNextHookEx is win32 api that can be loaded to .Net // using dll import like they did with setwindowshookex in example return CallNextHookEx(hHook, code, wParam, lParam); }

              1 Reply Last reply
              0
              • D darkelv

                Try setting the form's keypreview to true, then catch the key down of the form.

                I Offline
                I Offline
                Ilia Blank
                wrote on last edited by
                #7

                It will work only if the the form captured the input. As far as I unerstand the goal is to catch all keyborad key downs regardless to the current window.

                C 1 Reply Last reply
                0
                • I Ilia Blank

                  It will work only if the the form captured the input. As far as I unerstand the goal is to catch all keyborad key downs regardless to the current window.

                  C Offline
                  C Offline
                  C Scharbe
                  wrote on last edited by
                  #8

                  i want to catch all keyboard key downs which were sendet if any control in the current window is focused (without catching each key down of each control in the window.)

                  1 Reply Last reply
                  0
                  • D darkelv

                    Try setting the form's keypreview to true, then catch the key down of the form.

                    C Offline
                    C Offline
                    C Scharbe
                    wrote on last edited by
                    #9

                    i setted the keydownpreview true of the form and create a keydownpreview_event of the form, but the event does not trigger.

                    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