Jump to content
Sign in to follow this  
iXX

How to determine "any key" pressed?

Recommended Posts

iXX

I need script that will wait for any key from keyboard.

"HotKeySet" seems not provide this function.

Anyone knows?

Thanks...

Share this post


Link to post
Share on other sites
Melba23

iXX,

Many of us "know", but checking for "any key" gets us perilously close to keylogger territory. ;)

Why do you need to wait for "any key"? What exactly are you trying to do?

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
iXX

Keyloggers, hmm. I understand... ;)

Only I am trying is that "any key to continue" thing, nothing more.

Share this post


Link to post
Share on other sites
czardas

If you can send any key then it is not necessary to determine anything as the topic title would suggest. The following code should suffice.

Send("{ENTER}")

Share this post


Link to post
Share on other sites
Melba23

iXX,

I am trying is that "any key to continue" thing, nothing more

And I did not think you were looking for anything more - I was just pointing out the difficulty of doing what you want within the Forum Rules. :)

As you can decide which keys will allow your script to continue, why not define a limited number and then use _IsPressed? That way you avoid all the problems. ;)

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
iXX

Melba23:

Only few? Not enought.

But I just discovered maybe a better solution: Timer_GetIdleTime()

This affects mouse too, thinking... ;):)

Share this post


Link to post
Share on other sites
Melba23

iXX,

Only few? Not enought

And why not? Why must it be "any key"? What is wrong with "Press Enter to continue"?;)

maybe a better solution: Timer_GetIdleTime()

I was looking into that function the other day as a possible solution to this often-asked question and I ran into the same problem of differentiating between mouse and keyboard. :)

M23

Edit:

If you are interested, this is what I came up with:

#include <guiconstantsex.au3>
#include <timers.au3>

While 1
    If _WaitForKey() Then
        MsgBox(0, "Hi", "User activity")
    EndIf
WEnd

Func _WaitForKey()
    Local $iStart
    Local $aMPos = MouseGetPos()
    While 1
        $iCurrent = _Timer_GetIdleTime()
        $aMPos_Now = MouseGetPos()
        If $iCurrent < $iStart Then
            If $aMPos_Now[0] <> $aMPos[0] Or $aMPos_Now[1] <> $aMPos[1] Then
                $aMPos = $aMPos_Now
                Return 0
            EndIf
            Return 1
        Else
            $iStart = $iCurrent
        EndIf
        Sleep(10)
    WEnd
EndFunc

Of course there are more elegant ways to do it, but then you get close to forbidden waters again. :)

M23

Edited by Melba23
Added code

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
PhoenixXL

Only I am trying is that "any key to continue" thing, nothing more.

If this the only reason then u must have a GUI

then this code will sound helpful (hope so)

<snip>

Edited by Melba23
Code removed

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
Exit

<snip>

Edited by Melba23
Code removed

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
Melba23

All,

I am locking this thread because it seems those of you responding are incapable of understanding that the code you post is reading the entire keyboard and thus is able to distinguish which key has been pressed. As such it falls foul of the the keylogger ban to which I linked earlier - what is hard to understand in that post? :)

This "any key pressed" question comes up regularly and nearly always ends up getting locked. Just accept that although AutoIt is quite capable of doing this, you cannot discuss how to it in these forums. Do not PM me to argue about it - the site owner has decreed this ban and Mods are all ready to enforce it. :)

And furthermore my patience is getting really worn thin when the same people (you know who you are ;)) keep posting code which watches the whole keyboard - the next time it happens the poster is getting a holiday. ;)

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
Guest
This topic is now closed to further replies.
Sign in to follow this  

×