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
|
public class MyMessageFilterConsultationPrestation : IMessageFilter
{
private int WM_KEYDOWN = 0x100;
private const int VK_TAB = 0x09;
private const int VK_SHIFT = 0x10;
private const int VK_ESCAPE = 27;
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern short GetAsyncKeyState(int vkey);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern short GetKeyState(int virtualKeyCode);
Consultation_Prestations Fen = new Consultation_Prestations();
public MyMessageFilterConsultationPrestation(Consultation_Prestations nouveau)
{
Fen = nouveau;
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == Convert.ToInt32(WM_KEYDOWN))
{
// check the WParam property of the message which gets
// the key value, in this case we are looking for the virtual tab key,
// the value for which is VK_TAB == 0x09.
if (Fen.ContainsFocus)
{
#region TAB
if (m.WParam.ToInt32() == VK_TAB)
{
// Permet de savoir si la touche SHIFT est enfoncée
Boolean bShiftKeyDown = GetKeyState(VK_SHIFT) < 0;
//Traitement
return true;
}
#endregion
else if (m.WParam.ToInt32() == VK_ESCAPE)
{
//Traitement
return true;
}
}
}
return false;
} |
Partager