MrCreatoR

UserInput UDF - Read user input

18 posts in this topic

#1 ·  Posted (edited)

First of all, i want to say thanks to Firefox, for the _IsPressed UDFs library. I took from there the whole concept for this “remake” and the needed helper functions.

The idea here is to make the concept of _IsPressed function to work with more options, such as OR/AND operations, [:CLASS:]es, keys as strings (i.e: "{ESC}"), or simple groups.

 

; #FUNCTION# ===================================================================
; Name:             _UserInput_Read
; Description:      Check user input.
;
; Parameter(s):     $nHexStrKey - Hex or String key to check.
;                       [*] This parameter supports strings as used in HotKeySet() function.
;                       [*] To make an "OR" checking operation, use "|" delimiter between the keys/classes.
;                       [*] To make an "AND" checking operation, use "+" delimiter between the keys/classes.
;                       [*] This parameter accepts special CLASS name, bellow is the list of supported classes:
;                                                  [:ALLKEYS:]     - All possible keys (any key) except mouse events (combine with [:ALLMOUSE:] to read all inputs)
;                                                  [:ALPHA:]       - Standard Alpha keys
;                                                  [:ALLNUM:]      - Standard Numeric keys or Numpad keys
;                                                  [:NUMPAD:]      - Numpad keys
;                                                  [:NUMERIC:]     - Standard Numeric keys
;                                                  [:ALLFUNC:]     - F1 -> F24
;                                                  [:FUNC:]        - F1 -> F12
;                                                  [:FUNCSPEC:]    - F13 -> F24
;                                                  [:ARROW:]       - Up, Down, Left, Right
;                                                  [:ALLMOUSE:]    - All mouse buttons + Wheel scroll + Mouse Move
;                                                  [:MOUSEMOVE:]   - Mouse move
;                                                  [:WHEELDOWN:]   - Wheel button held down (pressed)
;                                                  [:WHEELSCROLL:] - Wheel scroll
;                                                  [:SPECIAL:]     - BACKSPACE, TAB, ENTER etc.
;
;                   $iWait      - [Optional] Wait untill the pressed key is released (default is 0, no wait).
;                                   in this case the return will include time (in milliseconds) the key has been held down.
;                                 NOTE: $iWait will fail on "+" operation and few mouse events (Wheel scroll and Mouse movement).
;
; Return Value(s):  Always return array with 2 elements. The values in these elements depends on $iWait/$nHexStrKey parameters:
;                                  [0] - If key(s) has been pressed, returns 1 or time representation if $iWait = 1, otherwise returns 0.
;                                  [1] - If key(s) has been pressed, returns pressed key (see bellow exceptions list), otherwise returns empty string ("").
;                                   * When using mouse classes ([:ALLMOUSE:]/[:MOUSEMOVE:]/[:WHEELDOWN:]/[:WHEELSCROLL:]),
;                                     there is an exception in return value, here is the list of return values depending on specified class:
;                                                                   [:ALLMOUSE:] - Returns:
;                                                                                           "MOUSE_MOVE" string if mouse has been moved
;                                                                                           "MOUSE_BUTTON" string if mouse wheel button has been pressed
;                                                                                           "MOUSE_SCROLL" string if mouse wheel has been scrolled
;                                                                   [:MOUSEMOVE:] - Returns "MOUSE_MOVE" string if mouse has been moved
;                                                                   [:WHEELDOWN:] - Returns "MOUSE_BUTTON" string if mouse wheel button has been pressed
;                                                                   [:WHEELSCROLL:] - Returns "MOUSE_SCROLL" string if mouse wheel has been scrolled
;                                                                   
;                                                                   
; Author(s):        G.Sandler (MrCreatoR)
; Note(s):          See examples to get idea of proper usage.
;===============================================================================
Simple example (Mixed keys usage):

#include <UserInput.au3>

HotKeySet('{ESC}', '_Quit')

While 1
    ;[QWERT] it's a Group, a set of characters (equivalent to 'Q|W|E|R|T')
    ;20 is a hex-value, wich is {Spacebar}.
    $aRead = _UserInput_Read('{CTRL}+S|20|[:ALPHA:]+[:ALLNUM:]|-|=|\|''|;|[QWERT]')
    
    If $aRead[0] Then
        _Output_Result($aRead[1])
    EndIf
    
    Sleep(10)
WEnd

Func _Output_Result($iKey)
    Local $sKeys = '', $aKeys = StringSplit($iKey, '+')
    
    ;Formate the output
    For $i = 1 To $aKeys[0]
        $sKeys &= '{' & _UserInput_GetKeyString($aKeys[$i]) & '}'
        If $i < $aKeys[0] Then $sKeys &= '+'
    Next
    
    Local $sTT_Data = StringFormat('_UserInput_Read Return:\t%s (%s)', $iKey, $sKeys)
    ToolTip($sTT_Data)
EndFunc

Func _Quit()
    Exit
EndFunc
===============================================================================

Attachments:

UserInput.zip

IsPressedEx_UDF.zip

Enjoy!

:)

Edited by MrCreatoR

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



@MrCreator

Nice job ! :)

I like the way to use '{ESC}', its another way of _GetKeyByAlpha('ESC')... :lmao:

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Great job on the IsPressedEx script! In looking through it in detail, I have however found one minor problem. The script that I just copied from the above link, does not see apostrophes('). I have found that the fix for this involves only two changes:

In IsPressedEx_UDF.au3:

line 103 (which is within function: _IsPressedEx())

reads:

$iKeysPressed = __KeysPressedCheck_Proc(1, 221, -1, $iWait, $iTFormat, $vDLL)

should be:

$iKeysPressed = __KeysPressedCheck_Proc(1, 222, -1, $iWait, $iTFormat, $vDLL)

the same correction in:

line 160 (which is within function: _IsPressedEx())

reads:

$iKeysPressed = __KeysPressedCheck_Proc(136, 221, -1, $iWait, $iTFormat, $vDLL)

should read:

$iKeysPressed = __KeysPressedCheck_Proc(136, 222, -1, $iWait, $iTFormat, $vDLL)

Thanks,

RW Baker


RW Baker

Share this post


Link to post
Share on other sites

Great job on the IsPressedEx script! In looking through it in detail, I have however found one minor problem. The script that I just copied from the above link, does not see apostrophes('). I have found that the fix for this involves only two changes:

In IsPressedEx_UDF.au3:

line 103 (which is within function: _IsPressedEx())

reads:

$iKeysPressed = __KeysPressedCheck_Proc(1, 221, -1, $iWait, $iTFormat, $vDLL)

should be:

$iKeysPressed = __KeysPressedCheck_Proc(1, 222, -1, $iWait, $iTFormat, $vDLL)

the same correction in:

line 160 (which is within function: _IsPressedEx())

reads:

$iKeysPressed = __KeysPressedCheck_Proc(136, 221, -1, $iWait, $iTFormat, $vDLL)

should read:

$iKeysPressed = __KeysPressedCheck_Proc(136, 222, -1, $iWait, $iTFormat, $vDLL)

Thanks,

RW Baker

Thanks, will be fixed (it's for [:ALLKEYS:] and [:SPECIAL:] classes, right?).

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Sorry...I've been away...Yes: [:ALLKEYS:] and [:SPECIAL:] classes.

RW Baker


RW Baker

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi Mr.Creator

This is really a must. I just downloaded it, and by teh descripton it will help a lot.

Sometime ago FireFox and others helped me in some similar solution, but what I implemented at the end was not so complete as yours.

Thanks

Jose

Edited by joseLB

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi nice work.

How do I get this to be detected once? I meant that if the function _IsPressedEx return 1 then its wont be true again unless at least one of the keys is released and pressed back...

EDIT: Disregards my question.

I found that it is implemented already by monitoring the time of the pressed key.

The __IsPressed_GetTime function helper helps here since the "$iWait" parameter can be set to very long time.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Hi there, was wondering about this script. Is it possible to make it work so that there is a different key for mose scrolling each way?

Now it is: If _IsPressedEx("[:WHEELSCROLL:]...

That only detect if the scroll button is used, I need it to detect if it scroll one way or the other. Is it possible?

Deathboy

Share this post


Link to post
Share on other sites

You probably know this already but dllcall("user32.dll", "...") would work the same as dllopen/close because 'user32.dll' and other common dlls are loaded in memory by AutoIt before the script is executed, and AutoIt will close the DLL itself when it exits.

Also could also save a few bytes by just adding _IsPressed() by itself.

Anyways nice script, good idea.


Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Hi,

i must say, its a very nice work. Tank you.

But i have a question.

How is it possible to found out what a key was pressed?

I am aware that this can be used for a keylogger>_< , but i want to make a ComboBox where can be used each key as a hotkey and i can´t use Hotkeyset function on this place, becouse the Hotkeyset function blocks the key. :)

This would be very nice if there are a way to use

_IsPressedEx("[:ALLKEYS:]", $hDll) and founds out what the key was pressed.

Sorry, for my bad english. I am russian, living in germany and have not so many practis in english. And normaly i am active in german AutoIt forums.

I hope someone can help me.

Share this post


Link to post
Share on other sites

@Igromanru

Hi,

You will find what you want here :

Or maybe here :

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ty FireFox.

But i have rewrote now the _IsPressedEx to _IsPressedExEx and now it returns the pressed key.

I will test it one more time and if it alowed, i will made a _IsPressedExEx thread.

Edited by Igromanru

Share this post


Link to post
Share on other sites

What is a practical usage example of this UDF? All the included examples merely display a tooltip showing $iRet = 1 and the $iExtended value, also for which I see no useful purpose. Please enlighten me.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Thank you for replying, JohnOne, but I would not have asked if its usefulness was clear to me.  I'm not trying to insult or question the author. I want to grasp its usefulness so I can perhaps use it. The functional results of the included examples is a tooltip that looks the same for almost every key pressed.  It may be as plain as the nose on your face but I'm simply not seeing it.

la3c.jpg

Please humor me with a real-world example.

Edited by timmy2

Share this post


Link to post
Share on other sites

Update...

v1.2 (09.02.2015)

* UDF renamed to UserInput.
* Better return handling (see examples).
* Changed functions usage concept (see examples).
* Many bug fixes.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

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