Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

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) Prosoft
Spain Spain
No Biography provided

Comments and Discussions

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