Jump to content



Photo

_IsPressedEx UDF - Extended _IsPressed function


  • Please log in to reply
12 replies to this topic

#1 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,244 posts

Posted 29 January 2009 - 06:26 AM

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.

Plain Text         
; #FUNCTION# =================================================================== ; Name:         _IsPressedEx ; Description:    Extended _IsPressed function to check if key has been pressed. ; ; Parameter(s):  $nHexStrKey - Hex or String key to check. ;                      [*] This parameter supports a 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. ;                      [*] And also have it's own CLASS list support: ;                                                 [:ALLKEYS:]    - All possible keys (any key) - @Extended = 1 ;                                                 [:ALPHA:]    - Standard Alpha keys - @Extended = 2 ;                                                 [:ALLNUM:]      - Standard Numeric keys or Numpad keys - @Extended = 3-4 ;                                                 [:NUMPAD:]      - Numpad keys - @Extended = 5 ;                                                 [:NUMERIC:]    - Standard Numeric keys - @Extended = 6 ;                                                 [:ALLFUNC:]    - F1 -> F24 - @Extended = 7 ;                                                 [:FUNC:]      - F1 -> F12 - @Extended = 8 ;                                                 [:FUNCSPEC:]  - F13 -> F24 - @Extended = 9 ;                                                 [:ARROW:]    - Up, Down, Left, Right - @Extended = 10 ;                                                 [:ALLMOUSE:]  - All mouse buttons+Wheel scroll+Mouse Move - @Extended = 11-14 ;                                                 [:MOUSEMOVE:]   - Mouse move - @Extended = 15 ;                                                 [:WHEELDOWN:]   - Wheel button held down (pressed) - @Extended = 16 ;                                                 [:WHEELSCROLL:] - Wheel scroll - @Extended = 17 ;                                                 [:SPECIAL:]    - BACKSPACE, TAB, ENTER etc. - @Extended = 18-22 ; ;                  $vDLL       - [Optional] Handle to dll or Default/-1 to user32.dll. ; ;                  $iWait     - [Optional] Wait untill the pressed key is released, ;                                 in this case the return will include time the key has been held down (pressed). ;                                  (default is 0, no wait). ;                                 [NOTE]: $iWait will fail on "+" operation and few mouse events (Wheel scroll and Mouse movement). ; ;                  $iTFormat   - [Optional] Time format to use when $iWait parameter is <> 0: ;                                                                   -1 - Return floating number of milliseconds (default). ;                                                                   1  - Return string with time format. ; ; Requirement(s):   AutoIt v3.2.10.0 +. ; ; Return Value(s):  On Success  - Depending on $iWait/$nHexStrKey parameters, ;                                 if it's 0, then return 1, otherwise check the parameter description. ;                                 @extended is set in accordance with passed class or string/hex keys: ;                                               @extended < 0 indicating on "+" operation, ;                                                -N => Here 'N' is the occurence number where the "AND" keys was found ;                                                 (in the "OR" list, i.e: "{F1}|CTRL+P", here @extended = -2 if CTRL+P is pressed). ;                                               @extended = 1 to 21, means the classes is used ;                                                (the extended code will include the value of checked class ;                                                 in the same order as it's appearing in the $nHexStrKey parameter's description). ;                                               @extended = 30 means that the key is non CLASS key, but one of the string/hex keys. ; ;                  On Failure  - Returns 0. ; ; Author(s):        MrCreatoR ;                  [Based on _IsPressed UDFs library by Firefox: http://www.autoitscript.com/forum/index.php?showtopic=86296]. ; ; Note(s):        See examples to get idea of properly usage. ;===============================================================================


Simple example (Mixed keys usage):

AutoIt         
#include <IsPressedEx_UDF.au3> HotKeySet("^q", "_Quit") $hU32_DllOpen = DllOpen("User32.dll")   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}.     $iRet = _IsPressedEx("{CTRL}+S|20|[:ALPHA:]+[:ALLNUM:]|-|=|\|'|;|[QWERT]", $hU32_DllOpen)         If $iRet = 1 Then _Output_IsPressedEx_Result($iRet, @Extended)         Sleep(50) WEnd Func _Output_IsPressedEx_Result($iRet, $iExtended)     Local $sTT_Data = StringFormat("+ _IsPressedEx Return:\t%s\n! @Extended code:\t%i (see docs for details)", $iRet, $iExtended)     ToolTip($sTT_Data) EndFunc Func _Quit()     DllClose($hU32_DllOpen)     Exit EndFunc

===============================================================================

Attachments:

Attached File  IsPressedEx_UDF.zip   8.71KB   1119 downloads

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

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team








#2 FireFox

FireFox

    What is dead may never die

  • MVPs
  • 3,516 posts

Posted 29 January 2009 - 04:27 PM

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

Cheers, FireFox.
OS : Win XP SP3 / Win 7 SP1 / Win 8 | Autoit version: latest stable / beta

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

Updated 22 April, 2013 - If you find dead links please send me a PM, do not post in the topics !

#3 Kip

Kip

    When done learning: die

  • Active Members
  • PipPipPipPipPipPip
  • 1,685 posts

Posted 29 January 2009 - 05:24 PM

Could be handy.
There's a big chance this post has been edited.Posted Image

#4 RWBaker

RWBaker

    Seeker

  • Active Members
  • 19 posts

Posted 27 February 2009 - 05:00 PM

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

#5 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,244 posts

Posted 09 March 2009 - 10:38 PM

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

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#6 RWBaker

RWBaker

    Seeker

  • Active Members
  • 19 posts

Posted 11 March 2009 - 02:21 PM

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

RW Baker
RW Baker

#7 joseLB

joseLB

    Polymath

  • Active Members
  • PipPipPipPip
  • 214 posts

Posted 09 November 2009 - 03:25 PM

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, 11 November 2009 - 09:49 PM.


#8 lsakizada

lsakizada

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 392 posts

Posted 11 November 2009 - 04:22 PM

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, 14 November 2009 - 09:05 AM.

Be Green Now or Never (BGNN)!

#9 Deathboy

Deathboy

    Seeker

  • Active Members
  • 30 posts

Posted 02 April 2010 - 05:07 PM

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

#10 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 02 April 2010 - 10:41 PM

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.
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#11 Igromanru

Igromanru

    Seeker

  • New Members
  • 2 posts

Posted 04 July 2011 - 07:49 AM

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.

#12 FireFox

FireFox

    What is dead may never die

  • MVPs
  • 3,516 posts

Posted 04 July 2011 - 01:13 PM

@Igromanru
Hi,
You will find what you want here :
http://www.autoitscript.com/forum/topic/90598-hotkeyinput-au3/
Or maybe here :
http://www.autoitscript.com/forum/topic/90492-hotkey-au3/page__hl__hotkey

Br, FireFox.
OS : Win XP SP3 / Win 7 SP1 / Win 8 | Autoit version: latest stable / beta

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

Updated 22 April, 2013 - If you find dead links please send me a PM, do not post in the topics !

#13 Igromanru

Igromanru

    Seeker

  • New Members
  • 2 posts

Posted 04 July 2011 - 05:24 PM

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, 04 July 2011 - 05:24 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users