Link to home
Start Free TrialLog in
Avatar of Max Destiny
Max Destiny

asked on

Keyboard

KeyboardDevice a = Keyboard.IsKeyUp(Key.A);


                  KeyboardDevice b = Keyboard.IsKeyUp(Key.B);


                  if (Keyboard.IsKeyUp(Key.A)
                        
                        {

                        Console.WriteLine(Key.A.ToString());
                  }
                  KeyGesture gest = new KeyGesture(Key.A,ModifierKeys.Control,Key.A.ToString());
                  if (gest)

                  {
                        Console.WriteLine(gest.DisplayString);

                  }

I'm trying to debug this for 1 hour and it doesn't show the gest.DisplayString
Avatar of it_saige
it_saige
Flag of United States of America image

Just at a glance this code is not correct.  
1.  IsKeyUp returns a boolean not a KeyboardDevice.
2.  gest is not a boolean.

The following code compiles for me:
using System;
using System.Windows.Input;

namespace EE_Q28996403
{
	class Program
	{
		[STAThread]
		static void Main(string[] args)
		{
			if (Keyboard.IsKeyUp(Key.A))
				Console.WriteLine(Key.A.ToString());

			var gesture = new KeyGesture(Key.A, ModifierKeys.Control, Key.A.ToString());
			if (gesture != default(KeyGesture))
				Console.WriteLine(gesture.DisplayString);

			Console.ReadLine();
		}
	}
}

Open in new window

And produces the expected output -User generated image
-saige-
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial