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. Detecting if a key is pressed outside the key events

Detecting if a key is pressed outside the key events

Scheduled Pinned Locked Moved C#
question
4 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
    Christian Wikander
    wrote on last edited by
    #1

    I want to detect if a key is held down during the start up of my program, i.e. in

    static void Main()

    Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.

    E R 2 Replies Last reply
    0
    • C Christian Wikander

      I want to detect if a key is held down during the start up of my program, i.e. in

      static void Main()

      Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.

      R Offline
      R Offline
      Roger Alsing 0
      wrote on last edited by
      #2

      Have a look at: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx[^] Im not 100% sure that it does work at program startup or if it have some assoiciaton with the wnd proc. But it I would guess it does work w/o wnd proc. If so, then you can simply call it ad the app main method.

      My Blog

      1 Reply Last reply
      0
      • C Christian Wikander

        I want to detect if a key is held down during the start up of my program, i.e. in

        static void Main()

        Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.

        E Offline
        E Offline
        Ed Poore
        wrote on last edited by
        #3

        One way I can think of is to add a reference to System.Windows.Forms if you don't have it already and use the following:

        static void Main(string[] args)
        {
        Keys modifiers = Control.ModifierKeys;
        Console.WriteLine(modifiers);
        }

        The modifiers enumeration will have the keys held down (only works for the modifier keys, i.e. Control, Shift, Alt etc).


        I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder

        C 1 Reply Last reply
        0
        • E Ed Poore

          One way I can think of is to add a reference to System.Windows.Forms if you don't have it already and use the following:

          static void Main(string[] args)
          {
          Keys modifiers = Control.ModifierKeys;
          Console.WriteLine(modifiers);
          }

          The modifiers enumeration will have the keys held down (only works for the modifier keys, i.e. Control, Shift, Alt etc).


          I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder

          C Offline
          C Offline
          Christian Wikander
          wrote on last edited by
          #4

          Thanks! This works like a charm!

          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