Page 1 sur 1

Fonction pour presser un bouton radio  

Posté : mer. 01 mai 2019 16:43
par littlechiki
Bonjour,
Je cherche à créer une fonction qui me permettrait de cocher un bouton radio simplement en appuyant sur une touche de mon clavier.
Imaginons que j'appuie sur la touche 1, un bouton radio se coche. en appuyant sur 2, un autre se coche.
Merci pour vos réponses !

Re: Fonction pour presser un bouton radio

Posté : mer. 01 mai 2019 17:18
par mikell
Il y a plusieurs façons, par exemple :

#include <GUIConstantsEx.au3>

GUICreate("", 225, 80)
$un = GUICtrlCreateRadio("touche 1", 10, 50, 65, 25)
$deux = GUICtrlCreateRadio("touche 2", 80, 50, 65, 25)
$d1 = GUICtrlCreateDummy()
$d2 = GUICtrlCreateDummy()
Local $aAccelKeys[2][2] = [["{NUMPAD1}", $d1],["{NUMPAD2}", $d2]]
GUISetAccelerators($aAccelKeys)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $d1
            GUICtrlSetState ($un, $GUI_CHECKED)
        Case $d2
            GUICtrlSetState ($deux, $GUI_CHECKED)
    EndSwitch
WEnd

Re: Fonction pour presser un bouton radio

Posté : mer. 01 mai 2019 19:01
par mdanielm
Sans Dummy:
GUICreate("", 225, 80)
   $un = GUICtrlCreateRadio("touche 1", 10, 50, 65, 25)
   $deux = GUICtrlCreateRadio("touche 2", 80, 50, 65, 25)
   GUISetState()

   do
      if _IsPressed("61") then
         GUICtrlSetState ($un, $GUI_CHECKED)
      elseif _IsPressed("62") then
         GUICtrlSetState ($deux, $GUI_CHECKED)
      EndIf
   until GUIGetMsg()=$GUI_EVENT_CLOSE

Re: Fonction pour presser un bouton radio

Posté : mer. 01 mai 2019 20:06
par walkson
Une autre méthode
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
GUICreate("", 225, 80)
$un = GUICtrlCreateRadio("touche 1", 10, 50, 65, 25)
$deux = GUICtrlCreateRadio("touche 2", 80, 50, 65, 25)
$trois = GUICtrlCreateRadio("touche 3", 150, 50, 65, 25)
HotKeySet("{NUMPAD1}", "un")
HotKeySet("{NUMPAD2}", "deux")
HotKeySet("{NUMPAD3}", "trois")
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func un()
GUICtrlSendMsg($un, $BM_CLICK , 1, 0)
EndFunc
Func deux()
GUICtrlSendMsg($deux, $BM_CLICK , 1, 0)
EndFunc
Func trois()
GUICtrlSendMsg($trois, $BM_CLICK , 1, 0)
EndFunc

Re: Fonction pour presser un bouton radio

Posté : mer. 01 mai 2019 22:02
par mikell
@walkson
Personnellement je ne recommanderais pas la méthode HotkeySet sur une touche, parce qu'elle accapare cette touche ce que ne font pas _IsPressed et les accélérators

Re: Fonction pour presser un bouton radio

Posté : mer. 01 mai 2019 22:26
par littlechiki
Merci à tous pour vos réponses ! avec ça, j'ai plein de façons de m'en sortir ! Merci merci !