LeaveKey, HoldKey

Nov 24, 2011 at 7:10 AM

Hi,

can you explain please when I need to use

Keyboard.Instance.HoldKey(sk);

and when

SomeWindow.Keyboard.HoldKey(sk);

It don't work for me in MFC project. All special keys one by one works perfect, but holding is not.

Say I want to HOME,HOLD-SHIFT,END,DELETE. 

It makes all home, end , delete stuff but it seems that somehow it not holding the button.

 

Thank you in advance.

Dec 12, 2011 at 6:35 AM
Edited Dec 12, 2011 at 6:39 AM

I had a requirement to enter value in a editable textblock and did it the following way and works all time.

Never used keyboard.Instance . not sure why it doesn't work. the following might be useful to you.

            Core.InputDevices.AttachedKeyboard kb = w.Keyboard;

            // Clear existing value using Keyboard : SendKeys
            kb.HoldKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL);
            kb.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.A);
            kb.LeaveKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL);

            kb.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.DELETE);

Dec 12, 2011 at 6:48 AM

Say I want to HOME,HOLD-SHIFT,END,DELETE.

Core.InputDevices.Keyboard.Instance.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.HOME);

Core.InputDevices.Keyboard.Instance.HoldKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
Core.InputDevices.Keyboard.Instance.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.END);
Core.InputDevices.Keyboard.Instance.LeaveKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);

Core.InputDevices.Keyboard.Instance.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.DELETE);