0

I'm trying to control the keystroke from kinect. For example, when my right hand move to right, it means I hold right arrow on the keyboard. I finished to write the code for the kinect, but I don't know how to make a custom keyboard device. I tried to use SendKey but it doesn't worked, because there is no hold key command. I also using loop, thread but it doesn't work too. I try to use kinect to control google earth via WPF application. Any move from kinect will be translated to the keyboard's press or hold, so that it can control google earth application. Any suggestion?
Best Regards,
C.Porawat

1
  • Have you got it fixed? Actually my aim is also to control google earth using Kinect. Can you give me guidance on how to do that?
    – Faizan
    Sep 25, 2014 at 7:46

2 Answers 2

1

There is no hold key state or event. When holding down a key on a keyboard, multiple key events are generated. This win32 example simulates the left key held down forever:

while(true)
{
    INPUT input =
    {
        INPUT_KEYBOARD
    };
    KEYBDINPUT tmp =
    {
        VK_LEFT,
        0,
        0,
        0,
        NULL
    };
    input.ki = tmp;
    SendInput(1, &input, sizeof(INPUT));
    ::Sleep(100);
}
1
  • have you tried a Sendkeys in a loop with a Sleep like this of 100ms? But that would block the Ui thread, so if possible do it from another thread. Mar 29, 2011 at 3:52
1

I got the answer. By using using System.Windows.Interop and System.Runtime.InteropServices. Then, using:

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, IntPtr dwExtraInfo);

Then, call the keyboard event when I want to used it by:

 keybd_event(0x27, 0, KEYEVENTF_KEYDOWN, new System.IntPtr()); //press right arrow on the keyboard

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.