From b84282309b65d0b0bd88a3a9cc0b6789119170ef Mon Sep 17 00:00:00 2001 From: FLOBOY-France Date: Mon, 7 Jun 2021 18:43:30 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20en=20utilisant=20l'appui=20et=20la?= =?UTF-8?q?=20rel=C3=A2che=20de=20la=20touche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GamePadToKeyboard/Classes/KeyboardSender.cs | 21 ++++++++++++++++----- GamePadToKeyboard/Program.cs | 8 ++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/GamePadToKeyboard/Classes/KeyboardSender.cs b/GamePadToKeyboard/Classes/KeyboardSender.cs index 6bea481..bc389e0 100644 --- a/GamePadToKeyboard/Classes/KeyboardSender.cs +++ b/GamePadToKeyboard/Classes/KeyboardSender.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace GamePadToKeyboard { @@ -14,6 +10,18 @@ public class KeyboardSender private const int VK_Return = 0x0D; //Constante pour la touche Return + public const ushort WM_KEYDOWN = 0x0100; + + public const ushort WM_KEYUP = 0x0101; + + [DllImport("user32.dll")] + static extern IntPtr GetActiveWindow(); + + + [DllImport("user32.dll")] //sends a windows message to the specified window + public static extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, int lParam); + + public static void SendReturn() { keybd_event(VK_Return, 0, 0, 0); @@ -21,7 +29,10 @@ public static void SendReturn() public static void SendKey(uint keyCode) { - keybd_event(keyCode, 0, 0, 0); //Simuler autre touche, liste disponible ici : http://www.kbdedit.com/manual/low_level_vk_list.html + //keybd_event(keyCode, 0, 0, 0); //Simuler autre touche, liste disponible ici : http://www.kbdedit.com/manual/low_level_vk_list.html + SendMessage(GetActiveWindow(), WM_KEYUP, VK_Return, 0); + SendMessage(GetActiveWindow(), WM_KEYDOWN, VK_Return, 0); + SendMessage(GetActiveWindow(), WM_KEYUP, VK_Return, 0); } } diff --git a/GamePadToKeyboard/Program.cs b/GamePadToKeyboard/Program.cs index 3a39416..50595b6 100644 --- a/GamePadToKeyboard/Program.cs +++ b/GamePadToKeyboard/Program.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OpenTK.Input; +using System; using System.Configuration; -using OpenTK.Input; namespace GamePadToKeyboard {