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. on is asctive or not ... how to find out if caplock is active or not

on is asctive or not ... how to find out if caplock is active or not

Scheduled Pinned Locked Moved C#
tutorial
2 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.
  • D Offline
    D Offline
    datainjector
    wrote on last edited by
    #1

    Hi i am inetrested in finding out if the caplock button is active or not ... Thats when the form loads... or if there is a way to like toggle the button to disable when it loads ... Thanks DaIn

    H 1 Reply Last reply
    0
    • D datainjector

      Hi i am inetrested in finding out if the caplock button is active or not ... Thats when the form loads... or if there is a way to like toggle the button to disable when it loads ... Thanks DaIn

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

      P/Invoke the native function GetKeyState:

      [DllImport("user32.dll")]
      private static extern short GetKeyState(int virtKey);

      You would then pass 20 (VK_CAPITAL) to get the CAPS LOCK key state. Fortunately (for good reason), the System.Windows.Forms.Keys enumeration members match up with the virtual key constants defined in winuser.h, so you can use (int)Keys.CapsLock instead for more readable code:

      short value = GetKeyState((int)Keys.CapsLock);
      bool on = (value & 0x0001) != 0;
      myButton.Enabled = !on;

      It's important to mask out the high-order bit so you can check the status of the low-order bit. This is documented in the Platform SDK documentation for the GetKeyState, see so that for more information.

      -----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