Click here to Skip to main content
Click here to Skip to main content

Tagged as

Simulate a keystroke in windows

, 22 Feb 2011 CPOL
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];
 
   GetKeyboardState((LPBYTE)&keyState);
   if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
       (!bState && (keyState[VK_NUMLOCK] & 1)) )
   {
   // Simulate a key press
      keybd_event( VK_NUMLOCK,
                   0x45,
                   KEYEVENTF_EXTENDEDKEY | 0,
                   0 );
 
   // Simulate a key release
      keybd_event( VK_NUMLOCK,
                   0x45,
                   KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                   0);
   }
}
 
void main()
{
   SetNumLock( TRUE );
}
 
Reference MSDN (Thanx to Victor Nijegorodov)

License

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

Share

About the Author

Mukit, Ataul
Chief Technology Officer Rational Technologies
Bangladesh Bangladesh
C++ is not C with classes, JQuery is not Javascript, Google Search is not Learning, Design Patterns are not fashion, A code written in 2005 is not backdated just because it's 2015
Follow on   Twitter

Comments and Discussions

 
GeneralRe: Extend it to what.. a full article? PinmemberMukit, Ataul23-Aug-11 21:16 
GeneralRe: I say it because you I think you must extend it before publi... PinmemberCaner Korkmaz23-Aug-11 4:40 
GeneralReason for my vote of 1 I agree with the others, copying a c... PinprotectorAspDotNetDev1-Sep-11 7:58 
GeneralReason for my vote of 1 It is copy and paste !!! PinmemberCaner Korkmaz23-Aug-11 2:10 
GeneralRe: Just becoz u knew it b4hand, doesn't mean everybody knows it... PinmemberMukit, Ataul23-Aug-11 4:18 
GeneralRe: I agree, all the OP has done is copy some code from somewher... PinprotectorAspDotNetDev1-Sep-11 7:54 
GeneralReason for my vote of 1 nothing new Pinmemberbomihsc24-Mar-11 13:47 
GeneralRe: nothing new to u.. so i guess u r entitled to give a 1... PinmemberMukit, Ataul26-Mar-11 18:57 
GeneralReason for my vote of 3 good PinmemberDiogny Aguilera22-Feb-11 7:06 
GeneralReason for my vote of 5 Good reference. If I used this, I wo... Pinmemberjonathanbeyre22-Feb-11 4:10 
GeneralReason for my vote of 1 Incomplete and badly researched Pinmemberwim ton21-Feb-11 22:56 
GeneralRe: I thought tips was not about extensive research.. just somet... PinmemberMukit, Ataul21-Feb-11 23:28 
General[My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberVictor Nijegorodov21-Feb-11 22:31 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberMukit, Ataul21-Feb-11 23:37 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberVictor Nijegorodov21-Feb-11 23:51 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberMukit, Ataul21-Feb-11 23:53 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberVictor Nijegorodov22-Feb-11 0:04 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberMukit, Ataul22-Feb-11 0:22 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberPrafullaVedante2-Mar-11 20:00 
GeneralRe: [My vote of 2] Is it a plagiarism or you just forgot to provide a link_ PinmemberMukit, Ataul4-Mar-11 20:14 

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 | Mobile
Web03 | 2.8.141022.2 | Last Updated 22 Feb 2011
Article Copyright 2011 by Mukit, Ataul
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid