hey there..can you please help me write a C program to put the Caps Lock on??

Recommended Answers

Here's a small snippet to turn on the Caps-Lock.

#include <windows.h>

int main() {
  if ( !GetKeyState(VK_CAPITAL) & 1 ) {
    // If caps lock is off, simulate keypress
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY, 0 );
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0 );
  }
  return 0;
}

Hope this …

Jump to Post

All 4 Replies

Here's a small snippet to turn on the Caps-Lock.

#include <windows.h>

int main() {
  if ( !GetKeyState(VK_CAPITAL) & 1 ) {
    // If caps lock is off, simulate keypress
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY, 0 );
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0 );
  }
  return 0;
}

Hope this helps.

If your C-compiler supports peek and poke, and you are running in DOS, then this should work :-

main()
{
  char st;
  peek(0,0x417,&st,1);
  st|=0x40;
  poke(0,0x417,&st,1);
}

Replace 0x40 with 0x20 to switch on Num Lock instead. 0x80 means toggle Insert key. 0x10 means switch on Scroll Lock.

If you are running in a Windows environment with a Windows C compiler, you can toggle Caps Lock with :-

BYTE bt=0;
keybd_event(VK_CAPITAL,bt,0,0);
keybd_event(VK_CAPITAL,bt,KEYEVENTF_KEYUP,0);

HTH,

If your C-compiler supports peek and poke, and you are running in DOS, then this should work :-

main()
{
  char st;
  peek(0,0x417,&st,1);
  st|=0x40;
  poke(0,0x417,&st,1);
}

Replace 0x40 with 0x20 to switch on Num Lock instead. 0x80 means toggle Insert key. 0x10 means switch on Scroll Lock.

HTH,

i tried the following code on Turbo C++ but it didn't work..

> i tried the following code on Turbo C++ but it didn't work..
Backwards compatibility will only take your fossil compiler so far on your nice new OS.

Please don't tell me you're using XP or Vista, with some multi-cored CPU and gigs of RAM and hard disk.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.