frankk Posted February 26, 2010 Share Posted February 26, 2010 Hello, I'm having a problem: I need a function to run while a key is pressed. Basically, I tried it with two functions (start and stop) that are bound by HotKeySet to {x down} and {x up}. But the second Hotkeyset seems to overwrite the first and always match for keypress and release of key x. Quite unexpected for me, since x down/up works for Send(). I'm sure, there is a way to achieve what I tried, but unfortunately I couldn't find a solution. I'd be very happy if someone could help me there. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 26, 2010 Moderators Share Posted February 26, 2010 frankk,Welcome to the AutoIt forum. It is not surprising at all. Send uses the codes which keys produce as they are pressed and released (different codes for the 2 actions). HoKeySet only fires the associated function as the specified key is operated - there is no separate function for the release.You need to use _IsPressed to detect the key being pressed. Perhaps something like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("Not running", 10, 10, 150, 20) $hCounter = GUICtrlCreateLabel("", 10, 50, 30, 30) GUISetState() $dll = DllOpen("user32.dll") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) Exit EndSwitch If _IsPressed("58", $dll) Then _RunFunction() WEnd Func _RunFunction() Local $iCount = 0 GUICtrlSetData($hLabel, "Running") Do $iCount += 1 GUICtrlSetData($hCounter, $iCount) Sleep(100) ; Idle a bit so you can see the counter increasing Until Not _IsPressed("58", $dll) GUICtrlSetData($hLabel, "Not running") GUICtrlSetData($hCounter, "") EndFuncYou do need to keep checking the _IsPressed function to detect the key release in your function - but as it usually contains a loop this is not too much of a problem.I hope that helps. Ask if anything is unclear. 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...
frankk Posted February 26, 2010 Author Share Posted February 26, 2010 (edited) thank you very much. looks fine to me. will give it a try. works fine Edited February 26, 2010 by frankk 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