1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <windows.h>
 
bool ok = true;
 
void unlockcaps( BOOL bState )
 
{
     ok = false;
 
     BYTE keyState[256];
 
     GetKeyboardState((LPBYTE)&keyState);
 
      if((bState && !(keyState[VK_CAPITAL] & 1)) ||  (!bState && (keyState[VK_CAPITAL] & 1)) )
      {
      // Simulate a key press
 
         keybd_event( VK_CAPITAL, 0x3A, KEYEVENTF_EXTENDEDKEY | 00 );
 
      // Simulate a key release
 
         keybd_event( VK_CAPITAL, 0x3A, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
      }
}
 
void simulate_capslock()
 
{
     if(ok){ 
              keybd_event(VK_CAPITAL, 0x3A, KEYEVENTF_EXTENDEDKEY | 00);
              Sleep(230);            
              keybd_event(VK_CAPITAL, 0x3A, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
     }
}
 
void check_pause()
{
     if(GetAsyncKeyState(VK_LCONTROL))
     {
         if(ok == true){ unlockcaps( FALSE ); ok = false; }
         else{ unlockcaps ( FALSE ); ok = true; }
     }
}
 
 
int main()
 
{
    while(1){
 
             simulate_capslock();
             Sleep(1);
             check_pause();
             Sleep(1);
             if(GetAsyncKeyState(VK_RCONTROL) && GetAsyncKeyState(VK_RSHIFT)){
               unlockcaps( FALSE );
               return 0;
            }
            Sleep(1);
    }
}