none
[DirectX.DirectInput] Récupérer une combinaison de touche RRS feed

  • Question

  • Bonjour,

    Je cherche à récupérer une combinaison de touche qu'un utilisateur aurait pu effectuer.

    Voici le code auquel je suis arrivé mais je ne vois pas comment récupérer la combinaison de touche :

    Code Snippet

    public class KeyboardHandler
    {
    public Window Owner { get; set; }

    public Device Keyboard { get; set; }

    private KeyboardState State = null;

    private Thread _threadKeyboard = null;

    public AutoResetEvent _keyboardUpdatedEvent = new AutoResetEvent(false);

    /// <summary>
    /// Initialize an instance of the KeyboardHandler for a keyboard management.
    /// </summary>
    /// <param name="win">The main window of the application.</param>
    public KeyboardHandler(Window win)
    {
    // Set Owner
    this.Owner = win;

    // Configure and acquire the keyboard
    this.Keyboard = new Device(SystemGuid.Keyboard);

    IntPtr hwnd = new WindowInteropHelper(win).Handle;
    this.Keyboard.SetCooperativeLevel(hwnd, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
    this.Keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
    this.Keyboard.SetEventNotification(this._keyboardUpdatedEvent);

    try
    {
    this.Keyboard.Acquire();
    }
    catch (DirectXException e)
    {
    Console.WriteLine(e.Message);
    }

    // Create thread
    this._threadKeyboard = new Thread(new ThreadStart(this.KeyboardUpdate));
    this._threadKeyboard.Start();
    }

    private void KeyboardUpdate()
    {
    while (true)
    {
    this._keyboardUpdatedEvent.WaitOne(-1, false);

    try
    {
    this.Keyboard.Poll();
    this.State = this.Keyboard.GetCurrentKeyboardState();

    Console.WriteLine("----- [ Key Group ] -----");
    for (Key k = Key.Escape; k <= Key.MediaSelect; k++)
    {
    if (this.State[k])
    {
    Console.WriteLine("----- [KEY] : " + k.ToString() + " -----");
    }
    }
    Console.WriteLine("----- [ Key End Group ] -----");
    }
    catch (NotAcquiredException)
    {
    try
    {
    this.Keyboard.Acquire();
    }
    catch (InputException ex)
    {
    Console.WriteLine(ex.Message);
    }
    }
    catch (InputException ex2)
    {
    Console.WriteLine(ex2.Message);
    }
    }
    }
    }



    Si j'appuye sur CTRL-A j'obtient ceci : (oui il détecte un clavier QWERTY alors qu'il ne devrais pas j'ai pas encore chercher pourquoi)

    Code Snippet

    ----- [ Key Group ] -----
    ----- [KEY] : LeftControl -----
    ----- [ Key End Group ] -----
    ----- [ Key Group ] -----
    ----- [KEY] : Q -----
    ----- [KEY] : LeftControl -----
    ----- [ Key End Group ] -----
    ----- [ Key Group ] -----
    ----- [KEY] : LeftControl -----
    ----- [ Key End Group ] -----
    ----- [ Key Group ] -----

    ----- [ Key End Group ] -----



    Auriez vous une idée ?



    Merci,
    Adrien Pellegrini.
    jeudi 28 août 2008 12:34

Toutes les réponses