Forcer capslock

cudenetf Messages postés 448 Date d'inscription mardi 20 septembre 2005 Statut Membre Dernière intervention 26 juillet 2012 - 22 juin 2006 à 17:28
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 23 juin 2006 à 19:21
bonjour,
j'aimerais forcer capslock a on
est-ce que cel est possible?
merci

6 réponses

scaryman Messages postés 492 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 16 mai 2007 12
22 juin 2006 à 17:47
Salut
J'ai trouvé ça mais je ne sais pas si ça marche :


[DllImport("user32.dll")]

private static extern int GetKeyboardState(ref byte pbKeyState);

[DllImport("user32.dll")]

private static extern int SetKeyboardState(byte[] lppbKeyState);


private void onButton_Click(object sender, System.EventArgs e)

{

byte[] keyState = new byte[256];


GetKeyboardState(ref keyState[0]);

keyState[VK_CAPITAL] = 1;

SetKeyboardState(keyState);

}


private void offButton_Click(object sender, System.EventArgs e)

{

byte[] keyState = new byte[256];


GetKeyboardState(ref keyState[0]);

keyState[VK_CAPITAL] = 0;

SetKeyboardState(keyState);

}

A++
0
bernie666 Messages postés 427 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 29 janvier 2008 1
22 juin 2006 à 17:48
    Salut

Je ne connais pas de fonction permettant de le faire mais que veux tu faire au juste ... si tu veux forcer quelqu'un a entrer une chaine en majuscul tu peux toujours contourner en utilisant la fonction ToUpper() sur une chaine.

Bonne soirée
0
cudenetf Messages postés 448 Date d'inscription mardi 20 septembre 2005 Statut Membre Dernière intervention 26 juillet 2012 2
23 juin 2006 à 06:36
ce serait bien la premeire solution
ar contre
pour le dllimport je ne vois pas comment l'integrer ds mon code (où)
je nl'ai mis a l'interieur de ma classe mais le compilateur le refuse


 
0
cudenetf Messages postés 448 Date d'inscription mardi 20 septembre 2005 Statut Membre Dernière intervention 26 juillet 2012 2
23 juin 2006 à 06:41
en fait c bon , j'ai trouvé il faut ecrire
[System.Runtime.InteropServices.

DllImport(
"user32.dll")]
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cudenetf Messages postés 448 Date d'inscription mardi 20 septembre 2005 Statut Membre Dernière intervention 26 juillet 2012 2
23 juin 2006 à 06:52
ensuite il faut la valeur de VK_capital
apparemeent c Ox14 (valeur hexadecimale)
par contre la led ne s'allume pas, quelqu'un sait il comment commander l'allumage de la led?
merci
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
23 juin 2006 à 19:21
Salut, il faut passer par SendInput :

public partial class Form1 : Form
{
    private const int INPUT_KEYBOARD = 1;
    private const int VK_CAPITAL = 0x14;
    private const int KEYEVENTF_KEYUP = 0x0002;


    [ StructLayout( LayoutKind.Sequential ) ]
    private struct KEYBDINPUT
    {
        public uint type;
        public ushort vk;
        public ushort scan;
        public uint flags;
        public uint time;
        public UIntPtr extraInfo;
        private uint padding0;
        private uint padding1;
    }


    [ DllImport( "user32.dll", SetLastError = true ) ]
    private static extern uint SendInput( uint num, [ In ] KEYBDINPUT[ ] inputs, int size );


    [ DllImport( "user32.dll" ) ]
    private static extern short GetKeyState( int vk );


    [ DllImport( "user32.dll" ) ]
    public static extern IntPtr GetMessageExtraInfo( );


    public Form1( )
    {
        InitializeComponent( );


        Button b = new Button( );
        b.Text = "CAPS LOCK";
        b.Click += delegate
        {            bool toggle ( GetKeyState( VK_CAPITAL ) & 0x0001 ) 1;


            if ( !toggle ) // toggle-off
            {
                KEYBDINPUT[ ] inputs = new KEYBDINPUT[ 2 ];
                inputs[ 0 ].type = INPUT_KEYBOARD;
                inputs[ 0 ].vk = VK_CAPITAL;
                inputs[ 0 ].flags = 0; // KeyDown
                inputs[ 0 ].extraInfo = ( UIntPtr )( int )GetMessageExtraInfo( );
                inputs[ 1 ].type = INPUT_KEYBOARD;
                inputs[ 1 ].vk = VK_CAPITAL;
                inputs[ 1 ].flags = KEYEVENTF_KEYUP;
                inputs[ 1 ].extraInfo = ( UIntPtr )( int )GetMessageExtraInfo( );


                SendInput( ( uint )inputs.Length, inputs, Marshal.SizeOf( typeof( KEYBDINPUT ) ) );
            }
        };
        this.Controls.Add( b );
    }
}
0
Rejoignez-nous