none
kinect mouse controll - KeyPress action gets stuck RRS feed

  • Question

  • Hi  there,

    maybe you guys can help me with my problem. I am a student and i am working for a software company. We developed a small kinect programm wich allows us to controll the mouse with it.

    One of the defined gestures is for KeyPress actions. You can assign every Key you want to it.

    Problem is, the key/button that you press keeps being pressed. That of course leeds to some

    problems.

    Even after closing down the mouseemulation programm, the button is still pressed. It simply can be resolved by pressing that button on the keyboard in order to release it.

    This part of the code schould be responsible for the KeyPress action, but i dont know whats wrong with it.

      /// <summary>
        /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
        /// </summary>
        /// <param name="keyCode">The VirtualKeyCode to press.</param>
        public void SimulateKeyPress(VirtualKeyCode keyCode)
        {
                   
          if (keyCode == VirtualKeyCode.Unknown)
          {
            return;
          }
             
          var input = new Input[1];
          input[0].Type = 1;
          input[0].Data.Keyboard = new KeyboardInput
          {
            Vk = (int)keyCode,
            Scan = 0,
            Flags = 0,
            Time = 0,
            ExtraInfo = IntPtr.Zero
          };
          SendInput(1, input, Marshal.SizeOf(input[0].GetType()));
          //first integer "1" stands for the number of Inputs
        }

    I am thankfull for any input!




    • Edited by brunobana Friday, May 24, 2013 1:08 PM
    Friday, May 24, 2013 1:05 PM

Answers

  • Hello brunobana.

    I think you should change the value of "flags".

    These are the values that I have used in KTOI.

            KEYEVENTF_EXTENDEDKEY = 0x0001;
            KEYEVENTF_KEYUP = 0x0002;
            KEYEVENTF_UNICODE = 0x0004;
            KEYEVENTF_SCANCODE = 0x0008

    For a single click I've used KEYEVENTF_SCANCODE.

    I hope it helps you.

    • Proposed as answer by BehnamGF Saturday, May 25, 2013 2:19 PM
    • Marked as answer by brunobana Friday, May 31, 2013 7:07 AM
    Saturday, May 25, 2013 2:18 PM
  • Hello brunobana.

    To combine two or more values just OR those values. For example

    Flags = KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE;

    Flags = 0x0002 | 0x0008 = 0x000A

    So you have both bits set.

    According to MSDN

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271(v=vs.85).aspx

    If KEYEVENTF_SCANCODE specified, wScan identifies the key and wVk is ignored. So you should put the key in wScan. If you want to use VK, I think you should set Flags to KEYEVENTF_KEYUP.

    About the comment, I think it's about KEYEVENTF_UNICODE not KEYEVENTF_SCANCODE . See the above MSDN link.

    Sending a keyboard message to software which uses DirectInput (Mostly games) is a little different than a software which doesn't. Take a look at KTOI source, maybe it helps you.

    Goodluck.

    • Proposed as answer by BehnamGF Thursday, May 30, 2013 7:52 AM
    • Marked as answer by brunobana Friday, May 31, 2013 7:07 AM
    Thursday, May 30, 2013 7:51 AM

All replies

  • Is this specifically related to the Kinect SDK? Are you using any of the Kinect controls from the toolkit?

    If not, you should ask over on the .Net forums since the SendInput/Interop is just creating a Windows Message and that message is passed to the respective applications. Typically you should be using the .Net api, SendKeys.

    http://msdn.microsoft.com/en-us/library/ms171548.aspx


    Friday, May 24, 2013 5:06 PM
  • Hello brunobana.

    I think you should change the value of "flags".

    These are the values that I have used in KTOI.

            KEYEVENTF_EXTENDEDKEY = 0x0001;
            KEYEVENTF_KEYUP = 0x0002;
            KEYEVENTF_UNICODE = 0x0004;
            KEYEVENTF_SCANCODE = 0x0008

    For a single click I've used KEYEVENTF_SCANCODE.

    I hope it helps you.

    • Proposed as answer by BehnamGF Saturday, May 25, 2013 2:19 PM
    • Marked as answer by brunobana Friday, May 31, 2013 7:07 AM
    Saturday, May 25, 2013 2:18 PM
  • Hello brunobana.

    I think you should change the value of "flags".

    These are the values that I have used in KTOI.

            KEYEVENTF_EXTENDEDKEY = 0x0001;
            KEYEVENTF_KEYUP = 0x0002;
            KEYEVENTF_UNICODE = 0x0004;
            KEYEVENTF_SCANCODE = 0x0008

    For a single click I've used KEYEVENTF_SCANCODE.

    I hope it helps you.

    ...i tried to set that flag to "KEYEVENTF_KEYUP" because i thougt this should be the right one.

    I`ll try "SCANCODE" now.

    But i got some more questions regarding this:

    When i read the Flags comments, there is mentioned that you can only set the "SCANCODE" value combined with the "KEYUP" value! But how can i set two values at the same time?

    Maybe like this:

    FLAGS = (uint)KeyboardFlag.Scancode & (uint)KeyboardFlag.Keyup,

    And there is also mentioned that the Vk Value must be 0, but how am i supposed to assign a Key if this Value is 0?

    See this Comment:

        /// <summary>
        /// KEYEVENTF_SCANCODE = 0x0008 (Windows 2000/XP: If specified, the system synthesizes a VK_PACKET keystroke. The V k parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. For more information, see the Remarks section.
        /// </summary>
        Scancode = 0x0008,
    Any Ideas - thanx again!
    Wednesday, May 29, 2013 7:06 AM
  • Hello brunobana.

    To combine two or more values just OR those values. For example

    Flags = KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE;

    Flags = 0x0002 | 0x0008 = 0x000A

    So you have both bits set.

    According to MSDN

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271(v=vs.85).aspx

    If KEYEVENTF_SCANCODE specified, wScan identifies the key and wVk is ignored. So you should put the key in wScan. If you want to use VK, I think you should set Flags to KEYEVENTF_KEYUP.

    About the comment, I think it's about KEYEVENTF_UNICODE not KEYEVENTF_SCANCODE . See the above MSDN link.

    Sending a keyboard message to software which uses DirectInput (Mostly games) is a little different than a software which doesn't. Take a look at KTOI source, maybe it helps you.

    Goodluck.

    • Proposed as answer by BehnamGF Thursday, May 30, 2013 7:52 AM
    • Marked as answer by brunobana Friday, May 31, 2013 7:07 AM
    Thursday, May 30, 2013 7:51 AM
  • ...thanx so much, you pointed me in the right direction! Everything is working fine now!

    Friday, May 31, 2013 7:07 AM