Does anyone know how to make this work?
Tim Orr
Ryan
Tim,
Not what you asked, but I can do this using keybd_event()
keybd_event(VK_SHIFT, 0, 0, 0);
keybd_event(VK_RIGHT, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
Note the use KEYEVENTF_EXTENDEDKEY as the cursor keys send two characters.
If you run this example below and press various keys (including the cursors)
you'll see what I mean:-
do {
printf("%d\n", c = getch());
} while (c != '\r');
My guess is that you need to find the equivalent of KEYEVENTF_EXTENDEDKEY in
SendInput().
HTH
--
Ritchie
Undo address for mail
keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
I got SendInput to work as well, here's the whole routine:
void handleKey(WORD vkKeyCode, bool keyIsDown)
{
INPUT key;
key.type = INPUT_KEYBOARD;
key.ki.wVk = vkKeyCode;
key.ki.wScan = 0;
key.ki.dwFlags = keyIsDown ? 0 : KEYEVENTF_KEYUP;
key.ki.time = 0;
key.ki.dwExtraInfo = 0;
// Need to mark the following keys as extended. Otherwise, SHIFT
// behaves very strangely with theses keys.
switch(vkKeyCode)
{
case VK_RIGHT:
case VK_LEFT:
case VK_UP:
case VK_DOWN:
case VK_END:
case VK_HOME:
case VK_INSERT:
case VK_DELETE:
case VK_NEXT:
case VK_PRIOR:
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
break;
}
UINT nEvents = SendInput(1, &key, sizeof(key));
}
"Ritchie" <rit...@commanddoline.co.uk> wrote in message
news:3dbecc9f$0$1288$cc9e...@news.dial.pipex.com...
void handleKey(WORD vkKeyCode, bool keyIsDown)
{
INPUT key;
key.type = INPUT_KEYBOARD;
key.ki.wVk = vkKeyCode;
key.ki.wScan = 0;
key.ki.dwFlags = keyIsDown ? 0 : KEYEVENTF_KEYUP;
key.ki.time = 0;
key.ki.dwExtraInfo = 0;
// Need to mark the following keys as extended. Otherwise, SHIFT
// behaves very strangely with theses keys.
switch(vkKeyCode)
{
case VK_RIGHT:
case VK_LEFT:
case VK_UP:
case VK_DOWN:
case VK_END:
case VK_HOME:
case VK_INSERT:
case VK_DELETE:
case VK_NEXT:
case VK_PRIOR:
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
break;
}
UINT nEvents = SendInput(1, &key, sizeof(key));
}
void doIt()
{
// fake a user pressing SHIFT-right arrow
handleKey(VK_SHIFT, true);
handleKey(VK_RIGHT, true);
handleKey(VK_RIGHT, false);
handleKey(VK_SHIFT, false);
}
"Ryan Schmitz" <ry...@earthsignal.com> wrote in message
news:7dzv9.55256$Sk6.5...@news1.telusplanet.net...
I'm glad you got it working. BTW, I use keybd_event() because try as I
might I cannot get anything to compile using SendInput! - way too many
structures for me and I can't quite get my head around the documention.
I've kept the code you posted, and I'll play with. Feel free to post
(to NG or email) any other examples.
Cheers,