Dim touche As Integer Public Sub form_KeyPress(KeyCode As Integer) ' private ? : pas testé If touche = VK_ESCAPE Then End Else If touche = VK_ENTER Then MsgBox ("taper return") End If End If End Sub Private Sub Command1_Click() ' alors on continue ............ msgbox "coucou return" End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() Form1.Caption = "ça sert à rien" Command1.Caption = "&Continuer" ' alt + C marche donc Command2.Caption = "&Annuler" ' alt + A marche donc Command1.Font.Bold = 10 Command2.Font.Bold = 10 SendKeyboardEvents = True ' LE TRUC !!!!!!!!!!!!!!! touche = KeyCode End Sub
Pour t'aider :Sans bouton, tu pourrais résumer tout ton code par ceci :Public Sub form_KeyPress(KeyCode As Integer)Select Case KeyCode Case vbKeyReturn: MsgBox "Return" Case vbKeyEscape: MsgBox "Escape"End SelectEnd SubLe passage par une variable 'touche' globale n'était pas très judicieux.Bon courage pour la suite !
effectivement, j'avais pas pensé à ça,sinon, mon pb était que la gestion des touches ne se chargeait pas avec la form (d'où le pb), donc je load "touche" avec le form en globale, sinon Keycode est toujours "empty"sinon, yep c'est d'la bricole avec les moyens du bord :-))
Ou alors utiliser l'API GetKeyState ;)
ATCHOUM !!!je vous demande pardons ???? *<:o((snif)
GetKeyState est une API qui te permet de connaitre l'etat d'une touche du clavier, petit exemple :Declare Function GetKeyState Lib "user32" ( _ ByVal nVirtKey As Long) As IntegerIf GetKeyState(VK_X) then msgbox "Touche X pressée"
Se souvenir du profil
Mot de passe oublié ? / Activation de compteCréer un compte
1 873 967 membres 0 nouveaux aujourd'hui 16 151 membres club