Danyg Posted January 29, 2016 Share Posted January 29, 2016 (edited) I'm looking for a function that gets the next keypress a user performs. If it's a specific key ("t"), it has to perform something. if it is anything else, it has to do something different. You would think that this would be easy using the IsPressed() function, but it can only detect for specific keys - I need a way to be able to detect if any key whatsoever has been pressed. Edited February 1, 2016 by Danyg Link to comment Share on other sites More sharing options...
Jfish Posted January 29, 2016 Share Posted January 29, 2016 (edited) Edit: read that too quickly. Edited January 29, 2016 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Danyg Posted January 29, 2016 Author Share Posted January 29, 2016 The problem with that approach is the "do something else" part will run if nothing is pressed. I need to wait (sleep) until something is pressed and then evaluate what was prsesed. If it was "t" then do something. If it was anything else, do something else. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2016 Moderators Share Posted January 29, 2016 Danyg, Welcome to the AutoIt forums. Checking for "the next keypress a user performs" gets us perilously close to keylogger territory - and as you can see from this announcement we have strict rules on what is allowed to be discussed in this forum. If you want to check for just a few keys, then _IsPressed or HotKeySet would be a sensible place to start looking in the Help file. 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...
Danyg Posted January 29, 2016 Author Share Posted January 29, 2016 1 minute ago, Melba23 said: Danyg, Welcome to the AutoIt forums. Checking for "the next keypress a user performs" gets us perilously close to keylogger territory - and as you can see from this announcement we have strict rules on what is allowed to be discussed in this forum. If you want to check for just a few keys, then _IsPressed or HotKeySet would be a sensible place to start looking in the Help file. M23 Hello M23 I am not interested in logging keys - Hell, I'm not even interested in what key was pressed (unless it was the one I'm using). If this is not okay to discuss on AutoIT Forums, then perhaps you can help me with my original problem. I have a function that I want to run whenever the PAUSE button is pressed, followed by a "t". If another key is pressed than t, the function should just cancel. HotKeySet("{PAUSE}", "Start") While 1 Sleep(100) WEnd Func Start() If _IsPressed(54) Then ;Do something Else ;Do nothing EndFunc Link to comment Share on other sites More sharing options...
Danyg Posted January 31, 2016 Author Share Posted January 31, 2016 Bump Link to comment Share on other sites More sharing options...
AutoBert Posted January 31, 2016 Share Posted January 31, 2016 about HotKeySet and test the example. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 31, 2016 Developers Share Posted January 31, 2016 The best alternative I can think of is to check for the "t" in the first x seconds after Pause was pressed. in case it isn't, you abandon the func. Anything else will be a sort of keylogger since you need to monitor all keystrokes. This is possible too but not to be discussed here as indicated. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 31, 2016 Moderators Share Posted January 31, 2016 @AutoBert in the future, how about offering suggestions without the constant RTFM vibe? Believe it or not, we're actually trying to welcome and encourage new folks to the forum mLipok and mikell 2 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Danyg Posted February 1, 2016 Author Share Posted February 1, 2016 Thanks for all the answers @AutoBert there is nothing useful in the HotKeySet example regarding my problem. I've decided to deploy @Jos example of checking for keypress for 3000 milliseconds, and it works great. Thank you all 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