1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Je déclare ceci dans ma classe
[DllImport("user32.dll", SetLastError = true)]
// Voici ma fonction qui va servir à simuler l'appuie des touches
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Appuie de la touche
public const int KEYEVENTF_KEYUP = 0x0002; //Relachement de la touche
//Les codes ci-après ne sont pas toujours juste ( 4 premières lettres testées )
public const int A = 0x41;
public const int B = 0x42;
public const int C = 0x43;
public const int D = 0x44;
public const int E = 0x45;
public const int F = 0x46;
public const int G = 0x47;
public const int H = 0x48;
public const int I = 0x49;
public const int J = 0x50;
public const int K = 0x51;
public const int L = 0x52;
public const int M = 0x53;
public const int N = 0x54;
public const int O = 0x55;
public const int P = 0x56;
public const int Q = 0x57;
public const int R = 0x58;
public const int S = 0x59;
public const int T = 0x60;
public const int U = 0x61;
public const int V = 0x62;
public const int W = 0x63;
public const int X = 0x64;
public const int Y = 0x65;
public const int Z = 0x66;
// Je crée ma fonction qui va appuyer sur les touches
public static void PressKeys()
{
System.Threading.Thread.Sleep(5000);
// APPUIE DE LA TOUCHE A
keybd_event(A, 0, KEYEVENTF_EXTENDEDKEY, 0); //appuie
keybd_event(A, 0, KEYEVENTF_KEYUP, 0); //relache
// PAUSE (temps en miliseconde)
System.Threading.Thread.Sleep(1000);
// APPUIE DE LA TOUCHE B
keybd_event(B, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(B, 0, KEYEVENTF_KEYUP, 0);
System.Threading.Thread.Sleep(1000);
// APPUIE DE LA TOUCHE C
keybd_event(C, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(C, 0, KEYEVENTF_KEYUP, 0);
System.Threading.Thread.Sleep(1000);
// APPUIE DE LA TOUCHE D
keybd_event(D, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(D, 0, KEYEVENTF_KEYUP, 0);
}
// Et jappelle ma fonction ou bon me semble |
Partager