4

Supposing I want to detect if the caps lock is active so if the keys are upper case, what can I use in c++ with windows?

I would need an equivalent of Console.CapsLock in C#

I already tried using GetAsyncKeyState(VK_CAPITAL) but I don't need the key state I need to know the "toggle" status

Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
Sam
  • 2,950
  • 1
  • 18
  • 26
  • 2
    I don't get how [this](https://stackoverflow.com/questions/13905342/winapi-how-to-get-the-caps-lock-state) doesn't answer your question. Please define the difference between the "key state" and "toggle status" in your own words. – Cory Kramer Oct 26 '15 at 13:02
  • 1
    @CoryKramer It doesn't tell me if it is active, it tells me when it is actually pressed – Sam Oct 26 '15 at 13:04
  • 3
    [GetKeyState()](http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) and `GetAsyncKeyState()` will return the toggle state of the key as well if it is up or down. It is stored in the least significant bit of the return. – NathanOliver Oct 26 '15 at 13:13
  • 1
    Console.CapsLock itself just calls GetKeyState(VK_CAPITAL) – Alex K. Oct 26 '15 at 13:16
  • Why are you adding `C#`? the OP is referring to a call from C# but the question is not about C#, it's about C++. – default Oct 26 '15 at 13:20

1 Answers1

6

The value from GeyKeyState (Win32) has a low order bit which gives its current toggle status.

Robinson
  • 9,666
  • 16
  • 71
  • 115
  • 3
    `(GetKeyState(VK_CAPITAL) & 0x0001) != 0` actually this worked thanks everyone – Sam Oct 26 '15 at 13:26