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. Application Level Key Shortcut

Application Level Key Shortcut

Scheduled Pinned Locked Moved C#
question
6 Posts 6 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
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?

    Richard Andrew x64R B A L 4 Replies Last reply
    0
    • J Jassim Rahma

      Hi, Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      You can use the PreviewKeyDown event to see what key is pressed at the Form level.

      The difficult we do right away... ...the impossible takes slightly longer.

      T 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        You can use the PreviewKeyDown event to see what key is pressed at the Form level.

        The difficult we do right away... ...the impossible takes slightly longer.

        T Offline
        T Offline
        Trak4Net
        wrote on last edited by
        #3

        As a side note to your answer you also need to set the KeyPreview property to true for the form.

        1 Reply Last reply
        0
        • J Jassim Rahma

          Hi, Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          Shortcuts generally work whichever control on a form has focus, unless the control explicitly steals that character (i.e. text boxes with Ctrl+C/X/Z/V). I think you need to put a shortcut handler on every form, though, if you want app-wide ones.

          1 Reply Last reply
          0
          • J Jassim Rahma

            Hi, Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?

            A Offline
            A Offline
            Andrei Straut
            wrote on last edited by
            #5

            Yes, it is, but you will have to go on treacherous ground to do so (needs some unmanaged code). Take a look at keyboard hooks, more specifically RegisterHotKey and UnregisterHotKey, both from user32.dll. Google it further, there are a lot of threads detailing how this can be achieved, for instance here[^], or here[^]

            Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

            1 Reply Last reply
            0
            • J Jassim Rahma

              Hi, Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If your application has an MDI form, you can create a menu item with the intended code and assign a shortcut to it. It would work "universally" in your entire application.

              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