Kikileu Posted May 19, 2019 Share Posted May 19, 2019 ok so, I have this this scrip for my work already finished but I cant find the way to press the button "send " with a key, it's annoying to have to maximize the gui every time I need to use it; hotkeyset and & º are the ways that I found but, they dont work me at all, there is another way to do it? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> HotKeySet("{F1}", "_SendDate" ) Local $vCurrentDate Local $_vCurrentDate #Region ### START Koda GUI section ### Form= Local $Form1 = GUICreate("Form1", 250, 170, 192, 124) Local $Input1 = GUICtrlCreateInput("", 110, 50, 105, 21) GUICtrlSetData(-1, "aaaa-mm-dd", "") GUICtrlSetState($input1, $GUI_DISABLE) Local $Button2 = GUICtrlCreateButton("(F1) Send", 90, 90, 75, 24) ;; Or ;~ Local $Button2 = GUICtrlCreateButton("$º Send", 90, 120, 75, 24) Local $Label1 = GUICtrlCreateLabel("Date1", 60, 53, 33, 17) Local $Radio1 = GUICtrlCreateRadio("Auto", 60, 17, 78, 17) GUICtrlSetState(-1, $GUI_CHECKED) Local $Radio2 = GUICtrlCreateRadio("Manual", 140, 17, 113, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Switch $nMsg Case $Button2 Select Case GUICtrlRead($Radio2) = 1 _SendDate (GUICtrlRead($Input1)) Case GUICtrlRead($Radio1) = 1 _SendDate () EndSelect Case $Radio1 if GUICtrlRead($Radio1) = $GUI_CHECKED Then GUICtrlSetState($input1, $GUI_DISABLE) EndIf Case $Radio2 if GUICtrlRead($Radio2) = $GUI_CHECKED Then GUICtrlSetState($input1, $GUI_ENABLE) EndIf EndSwitch WEnd Func _SendDate ($_vCurrentDate = "(F1) Send") Local $vCurrentDate = $_vCurrentDate = "(F1) Send" ? StringRight(@Year, 4) & ("-") & StringFormat("%02u-%02u", @MON, @MDAY) : $_vCurrentDate WinActivate ("Untitle - Notepad", "") WinWaitActive ("Untitle - Notepad", "", 0) Send ($vCurrentDate) Send("{ENTER}") EndFunc Link to comment Share on other sites More sharing options...
Subz Posted May 19, 2019 Share Posted May 19, 2019 With HotKeySet you can't use parameters in the function call, all parameters are ignored. You shouldn't use HotKeys that are used frequently by other programs like F1, so use something like Ctrl+F1, see example code below: nb: Not sure why but your default "Untitle - Notepad" is "Untitled - Notepad" on my system, so you may need to change it. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> HotKeySet("^{F1}", "_SendDate") Global $g_vCurrentDate GUICreate("Example", 250, 170, 192, 124) Global $g_idDateInput = GUICtrlCreateInput("", 110, 50, 105, 21) GUICtrlSetData(-1, "aaaa-mm-dd", "") GUICtrlSetState($g_idDateInput, $GUI_DISABLE) Global $g_idSendButton = GUICtrlCreateButton("(F1) Send", 90, 90, 75, 24) GUICtrlCreateLabel("Date1", 60, 53, 33, 17) Global $g_idRadio1 = GUICtrlCreateRadio("Auto", 60, 17, 78, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $g_idRadio2 = GUICtrlCreateRadio("Manual", 140, 17, 113, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $g_idSendButton Select Case GUICtrlRead($g_idRadio2) = 1 $g_vCurrentDate = GUICtrlRead($g_idDateInput) _SendDate () Case GUICtrlRead($g_idRadio1) = 1 $g_vCurrentDate = GUICtrlRead($g_idDateInput) _SendDate () EndSelect Case $g_idRadio1 If GUICtrlRead($g_idRadio1) = $GUI_CHECKED Then GUICtrlSetState($g_idDateInput, $GUI_DISABLE) EndIf Case $g_idRadio2 If GUICtrlRead($g_idRadio2) = $GUI_CHECKED Then GUICtrlSetState($g_idDateInput, $GUI_ENABLE) EndIf EndSwitch WEnd Func _SendDate () If $g_vCurrentDate = "" Then $g_vCurrentDate = "(F1) Send" $g_vCurrentDate = $g_vCurrentDate = "(F1) Send" ? StringRight(@Year, 4) & ("-") & StringFormat("%02u-%02u", @MON, @MDAY) : $g_vCurrentDate WinActivate ("Untitled - Notepad", "") WinWaitActive ("Untitled - Notepad", "", 0) Send ($g_vCurrentDate) Send("{ENTER}") $g_vCurrentDate = "" ;~ Reset the variable to blank EndFunc Link to comment Share on other sites More sharing options...
mikell Posted May 19, 2019 Share Posted May 19, 2019 (edited) May I suggest to read this page of the help file to "associate a gui button with a key" Edited May 19, 2019 by mikell Jfish, Subz and Kikileu 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now