Click here to Skip to main content
12,402,666 members (74,967 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.6K views
Posted

Simulate a keystroke in windows

, 1 Sep 2011 CPOL
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 --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 1 Sep 2011
Article Copyright 2011 by Jose David Pujo
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid