Click here to Skip to main content
13,046,356 members (69,533 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.2K views
Posted 1 Sep 2011

Simulate a keystroke in windows

, 1 Sep 2011
Rate this:
Please Sign up or sign in to vote.
With SendInput:void SetNumLock (bool active){ BYTE keyState[256]; GetKeyboardState((LPBYTE)&keyState); bool active0= keyState[VK_NUMLOCK] & 1; if (active0!=active) { INPUT inp[2]; ZeroMemory(inp, sizeof(inp)); inp[0].type=INPUT_KEYBOARD; ...

With SendInput:


void SetNumLock (bool active)
{
    BYTE keyState[256]; GetKeyboardState((LPBYTE)&keyState);
    bool active0= keyState[VK_NUMLOCK] & 1;
    if (active0!=active) {
         INPUT inp[2]; ZeroMemory(inp, sizeof(inp));
 
          inp[0].type=INPUT_KEYBOARD;
          inp[0].ki.dwFlags=0;
          inp[0].ki.wVk= VK_NUMLOCK;
 
          inp[1].type=INPUT_KEYBOARD;
          inp[1].ki.dwFlags=KEYEVENTF_KEYUP;
          inp[1].ki.wVk=VK_NUMLOCK;
 
        SendInput(2, inp, sizeof(INPUT));
    }
}

License

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

Share

About the Author

Jose David Pujo
Software Developer (Senior) Freelancer
Spain Spain
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 1 Sep 2011
Article Copyright 2011 by Jose David Pujo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid