Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendInput and VK_SHIFT using C++

Status
Not open for further replies.

PHH1955

Programmer
Jul 8, 2003
16
I'm trying to use SendInput to send keystrokes from my application to another application in a different thread.

I can accomplish sending character keys without a problem.

The problem arises when I try to send, non-character keys, specifically VK_SHIFT. The target application simply doesn't respond to the shift key when using SendInput.

I've searched and read everything I can find, trying everything including AttachThreadInput and Get/SetKeyboardState. Nothing seems to work, so I'd like to start over and see if anyone on this site can help provide a solution.

Here's the code that I used at the beginning of this project:
----------------------------------------------------------
INPUT arrayKeyBDIn[5];
arrayKeyBDIn[0].type = INPUT_KEYBOARD;
arrayKeyBDIn[0].ki.dwExtraInfo = 0;
arrayKeyBDIn[0].ki.time = 0;
arrayKeyBDIn[1].type = INPUT_KEYBOARD;
arrayKeyBDIn[1].ki.dwExtraInfo = 0;
arrayKeyBDIn[1].ki.time = 0;
arrayKeyBDIn[2].type = INPUT_KEYBOARD;
arrayKeyBDIn[2].ki.dwExtraInfo = 0;
arrayKeyBDIn[2].ki.time = 0;
arrayKeyBDIn[3].type = INPUT_KEYBOARD;
arrayKeyBDIn[3].ki.dwExtraInfo = 0;
arrayKeyBDIn[3].ki.time = 0;

//Set up a SHIFT 0 (zero)
arrayKeyBDIn[0].ki.wVk = VK_SHIFT;
arrayKeyBDIn[0].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
arrayKeyBDIn[0].ki.dwFlags = KEYEVENTF_SCANCODE;

arrayKeyBDIn[1].ki.wVk = 0x30;
arrayKeyBDIn[1].ki.wScan = MapVirtualKey(0x30, 0);
arrayKeyBDIn[1].ki.dwFlags = KEYEVENTF_SCANCODE;

arrayKeyBDIn[2].ki.wVk = 0x30;
arrayKeyBDIn[2].ki.wScan = MapVirtualKey(0x30, 0);
arrayKeyBDIn[2].ki.dwFlags =
KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP;

arrayKeyBDIn[3].ki.wVk = VK_SHIFT;
arrayKeyBDIn[3].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
arrayKeyBDIn[3].ki.dwFlags =
KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP;

//Make target window have focus and send keys
BringWindowToTop(hwndTargetMainWindow);
SendInput(4, arrayKeyBDIn, sizeof(INPUT));
----------------------------------------------------------
This code will work when Notepad is the target window, but not for another application that I am attempting to use that is not a microsoft product.

Anyone have experience with this type of application?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top