Jump to content

Stop Hot Key functionality


Recommended Posts

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 by autoitquestion
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@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 by Azraelsub7
Link to comment
Share on other sites

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

Hum. Yeah, don't know where I was with my mind. Thanks. :P

@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 .

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...