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 {