Danyg

Next Keypress [Solved]

10 posts in this topic

#1 ·  Posted (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 by Danyg

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

smiley38.gif  about HotKeySet and test the example. 

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@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 ;)

2 people like this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
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