autoitquestion Posted April 10, 2011 Share Posted April 10, 2011 (edited) Hi, What can I do in order Enter will return to its functionality? Here I wish that when program is active enter will click on Run button, but when it will not be active, enter will retrun to regular functionality Local $scanU, $enter=1 GUICreate("MyProg",300,300) GUISetState(@SW_SHOW) GUICtrlCreateLabel("Enter your input:", 30, 50, 120) $scanU = GUICtrlCreateInput("", 150, 50, 100, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btn = GUICtrlCreateButton("Run", 120, 200, 60, 20) GUISetState() If WinActive("[CLASS:AutoIt v3 GUI]") Then HotKeySet("{ENTER}", "_FuncEnter") Else $enter=0 EndIf $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ... EndSelect WEnd Func _FuncEnter() ControlClick ( "MyProg", "Run", "[CLASS:Button; INSTANCE:1]" ) EndFunc Thanks a lot for all your help! Noa Edited April 10, 2011 by autoitquestion Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 10, 2011 Moderators Share Posted April 10, 2011 autoitquestion,Look at GUISetAccelerators in the Help file. Accelerator keys act in a similar manner to HotKeys, but only when your GUI is active. Try to get them working and come back if you run into problems. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
andrei0x309 Posted April 10, 2011 Share Posted April 10, 2011 You could fallow Melba23 advice , or you could do it this way ( but is uglier ) : $dll = DllOpen("user32.dll") ... While $msg <> $GUI_EVENT_CLOSE If _IsPressed("0D", $dll) and WinActive("[CLASS:AutoIt v3 GUI]") Then _FuncEnter() Endif $msg = GUIGetMsg() Select Case $msg = $btn ... EndSelect WEnd ... DllClose($dll Link to comment Share on other sites More sharing options...
autoitquestion Posted April 10, 2011 Author Share Posted April 10, 2011 (edited) Melba23- I did as you suggested and it's really working!!! thx a lot Edited April 10, 2011 by autoitquestion Link to comment Share on other sites More sharing options...
Newb Posted April 10, 2011 Share Posted April 10, 2011 You could fallow Melba23 advice , or you could do it this way ( but is uglier ) : $dll = DllOpen("user32.dll") ... While $msg <> $GUI_EVENT_CLOSE If _IsPressed("0D", $dll) and WinActive("[CLASS:AutoIt v3 GUI]") Then _FuncEnter() Endif $msg = GUIGetMsg() Select Case $msg = $btn ... EndSelect WEnd ... DllClose($dll Just a question. The event about this stopping the functionality of the hotkeys is DLL closing? If so, this means I can stop and call back in Hotkey working/not working at will while executing the various steps of a script by dll opening and closing? I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 10, 2011 Moderators Share Posted April 10, 2011 Newb,I think you have misunderstood. The code you reposted uses _IsPressed to detect ENTER being pressed. As it says in the Help file, you should open/close user32.dll if you call the function repeatedly - which Azraelsub7 correctly did.Doing this has no effect on HotKeys. You turn them off by setting them with no function name - and back on by setting them with a valid function name.All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
andrei0x309 Posted April 10, 2011 Share Posted April 10, 2011 (edited) @Newb No i don't think so , i think DllClose is probably the some kind implementation for freelibrary , so you can even delete that line and the code will still work , but is better to use it as i don't know if the autoit interpreter does the clean up . So DllClose is used cause _ispressed is calling the getasynckey form user32.dll . Basically what you do is asking continuously the Operating System if that key is pressed , normally a sleep command must exist in the loop , else autoit will use a lot of cpu , anyway the sleep time must not be to great cause you will miss when the key is pressed , 100 milliseconds is a good choise , but i do not like to use getasynckey cause it has a lot of disadvantages , mostly you can use hooks , some languages have build in Key Pressed events , i think using events is a better way then using getasynckey function . Edited April 10, 2011 by Azraelsub7 Link to comment Share on other sites More sharing options...
Newb Posted April 10, 2011 Share Posted April 10, 2011 Newb,I think you have misunderstood. The code you reposted uses _IsPressed to detect ENTER being pressed. As it says in the Help file, you should open/close user32.dll if you call the function repeatedly - which Azraelsub7 correctly did.Doing this has no effect on HotKeys. You turn them off by setting them with no function name - and back on by setting them with a valid function name.All clear? M23Hum. Yeah, don't know where I was with my mind. Thanks. @NewbNo i don't think so , i think DllClose is probably the some kind implementation for freelibrary , so you can even delete that line and the code will still work , but is better to use it as i don't know if the autoit interpreter does the clean up .So DllClose is used cause _ispressed is calling the getasynckey form user32.dll .Basically what you do is asking continuously the Operating System if that key is pressed , normally a sleep command must exist in the loop , else autoit will use a lot of cpu , anyway the sleep time must not be to great cause you will miss when the key is pressed , 100 milliseconds is a good choise , but i do not like to use getasynckey cause it has a lot of disadvantages , mostly you can use hooks , some languages have build in Key Pressed events , i think using events is a better way then using getasynckey function .Yeah, I realized later. Thanks. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. 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