Click here to Skip to main content
11,573,642 members (62,563 online)
Click here to Skip to main content

Tagged as

Simulate a keystroke in windows

, 22 Feb 2011 CPOL 22.4K 7
Rate this:
Please Sign up or sign in to vote.
This tip shows how to simulate a key stroke in windows environment
void SetNumLock( BOOL bState )
   BYTE keyState[256];
   if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
       (!bState && (keyState[VK_NUMLOCK] & 1)) )
   // Simulate a key press
      keybd_event( VK_NUMLOCK,
                   KEYEVENTF_EXTENDEDKEY | 0,
                   0 );
   // Simulate a key release
      keybd_event( VK_NUMLOCK,
void main()
   SetNumLock( TRUE );

Reference MSDN (Thanx to Victor Nijegorodov)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mukit, Ataul
Chief Technology Officer Rational Technologies
Bangladesh Bangladesh
Your Lord does not like people who waste by extravagance, and only the righteous C s, and does so in increments, and they are of those people who are mindful of what memory and time has in offer and they waste none of it.

You may also be interested in...

Comments and Discussions

GeneralRe: Extend it to what.. a full article? Pin
Mukit, Ataul23-Aug-11 21:16
memberMukit, Ataul23-Aug-11 21:16 
GeneralRe: I say it because you I think you must extend it before publi... Pin
Caner Korkmaz23-Aug-11 4:40
memberCaner Korkmaz23-Aug-11 4:40 
GeneralReason for my vote of 1 I agree with the others, copying a c... Pin
AspDotNetDev1-Sep-11 7:58
protectorAspDotNetDev1-Sep-11 7:58 
GeneralReason for my vote of 1 It is copy and paste !!! Pin
Caner Korkmaz23-Aug-11 2:10
memberCaner Korkmaz23-Aug-11 2:10 
GeneralRe: Just becoz u knew it b4hand, doesn't mean everybody knows it... Pin
Mukit, Ataul23-Aug-11 4:18
memberMukit, Ataul23-Aug-11 4:18 
GeneralRe: I agree, all the OP has done is copy some code from somewher... Pin
AspDotNetDev1-Sep-11 7:54
protectorAspDotNetDev1-Sep-11 7:54 
GeneralReason for my vote of 1 nothing new Pin
bomihsc24-Mar-11 13:47
memberbomihsc24-Mar-11 13:47 
GeneralRe: nothing new to u.. so i guess u r entitled to give a 1... Pin
Mukit, Ataul26-Mar-11 18:57
memberMukit, Ataul26-Mar-11 18:57 
GeneralReason for my vote of 3 good Pin
Diogny Aguilera22-Feb-11 7:06
memberDiogny Aguilera22-Feb-11 7:06 
GeneralReason for my vote of 5 Good reference. If I used this, I wo... Pin
jonathanbeyre22-Feb-11 4:10
memberjonathanbeyre22-Feb-11 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 22 Feb 2011
Article Copyright 2011 by Mukit, Ataul
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid