Jump to content

IsPressed_UDF ! v2.3 | Advanced keypress


FireFox
 Share

Recommended Posts

IsPressed_UDF is based on original _IsPressed function.

Description :
-This udf can detect if some keys are pressed by user on keyboard or mouse.
-IsPressed functions extend possibility to choice keys to check.
-Keys are specified in functions by their hexadecimal number,
['0D' = 'ENTER'] you can also translate hexadecimal key to alpha key (see functions and examples)

Update : [Latest: 12 Jun 2013]

Version 1.2


_GetKeyByHex ;Thanks to AlmarM for idea
_GetKeyByAlpha


Version 1.3
__KeyPressCheck ;Thanks to Valuater for function


Version 1.4
__GetKeyType ;Thanks to Valuater for function


Version 1.5
Fixed __GetKeyType *No lower case (thanks to Manadar)
*Replaced "Keypad 0-9" to "Num 0-9"

Fixed _IsFuncKeyPressed *Added F13 to F24 keys
*Extended parameters included
*$Extended = 1 then Include F13 to F24 keys

Fixed _IsSpecialKeyPressed *Removed F13 to F24 keys


Version 1.6
Modified __GetKeyType *$Type = 0 Return Alpha
1 Return Hexadecimal


Version 1.7
Modified _IsSpecialKeyPressed;now extended to DD hexadecimal key
Modified __GetKeyType;now extended to DD hexadecimal key


Version 1.8
_IsWhellKeyScroll ;Thanks to MrCreator for function


Version 1.9
Fixed _IsWhellKeyScroll;now returns False after wheel scrolled (thanks to MrCreator)
Added _IsTimeKeyPressed
Added __DLL


Version 2.0
Fixed _IsTimeKeyPressed ;now working
Removed __DLL
Added DllOpen/Close user32.dll


Version 2.1
Changed work Whell to Wheel;Thanks to Paulie
Updated _IsWheelKeyScroll to better function


Version 2.2
Fixed OnAutoItExit function in order to work with the lastest AutoIt3 version


Version 2.3
Removed _IsPressed function and added Misc include to avoid duplicate func error



Functions :


_IsAnyKeyPressed
_IsOrKeyPressed
_IsAndKeyPressed
_IsAlphaKeyPressed
_IsNumKeyPressed
_IsAlphaNumKeyPressed
_IsFuncKeyPressed
_IsArrowKeyPressed
_IsMouseKeyPressed
_IsSpecialKeyPressed
_IsWheelKeyScroll
_IsTimeKeyPressed
_GetKeyByHex
_GetKeyByAlpha


__KeyPressCheck
__GetKeyType
Include _IsPressed



Exemples :


IsAnyKeyPressed
#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsAnyKeyPressed
; Parameter(s) : Check all keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsAnyKeyPressed() Then
MsgBox(64, "_IsAnyKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsOrKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsOrKeyPressed
; Parameter(s) : Check "ESC|ENTER|LEFT CLICK" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsOrKeyPressed("1B|0D|01") Then
MsgBox(64, "_IsOrKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsAndKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsAndKeyPressed
; Parameter(s) : Check "CTRL|ALT|DEL" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsAndKeyPressed("11|12|2E") Then
MsgBox(64, "_IsAndKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsAlphaKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsAlphaKeyPressed
; Parameter(s) : Check "Alpha" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsAlphaKeyPressed() Then
MsgBox(64, "_IsAlphaKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsNumKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsNumKeyPressed
; Parameter(s) : Check "Numeric" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsNumKeyPressed() Then
MsgBox(64, "_IsNumKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsAlphaNumKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsAlphaNumKeyPressed
; Parameter(s) : Check "Alpha" and "Numeric" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsAlphaNumKeyPressed() Then
MsgBox(64, "_IsNumKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsFuncKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsFuncKeyPressed
; Parameter(s) : Check "functions" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsFuncKeyPressed() Then
MsgBox(64, "_IsFuncKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsArrowKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsArrowKeyPressed
; Parameter(s) : Check "arrow" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsArrowKeyPressed() Then
MsgBox(64, "_IsArrowKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsMouseKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsMouseKeyPressed
; Parameter(s) : Check "mouse" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsMouseKeyPressed() Then
MsgBox(64, "_IsMouseKeyPressed", "Key pressed !", 1)
EndIf
WEnd

_IsSpecialKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsSpecialKeyPressed
; Parameter(s) : Check "special" keys
; Author(s): FireFox
;===============================================================================
While 1
If _IsSpecialKeyPressed() Then
MsgBox(64, "_IsSpecialKeyPressed", "Key pressed !", 1)
EndIf
WEnd

__GetKeyType

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _GetKeyType
; Parameter(s) : Return Hexadecimal key of specified alpha key
; Author(s): FireFox
;===============================================================================
MsgBox(64,"__GetKeyType",__GetKeyType("ESC",1))

While 1
If _IsOrKeyPressed(__GetKeyType("ESC",1)) Then
MsgBox(64,"__GetKeyByType","Key pressed !", 1)
EndIf
WEnd
#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : __GetKeyType
; Parameter(s) : Return Alpha key of specified Hexadecimal key
; Author(s): FireFox
;===============================================================================

MsgBox(64,"__GetKeyType",__GetKeyType("1B",1))

_IsWhellKeyScroll

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsWheelKeyScroll
; Parameter(s) : Returns 1 if wheel mouse key scrolled up or down
; Author(s): MrCreator,FireFox
;===============================================================================

While 1
If _IsWheelKeyScroll() Then
MsgBox(64, "_IsWheelKeyScroll", "Key scrolled !", 1)
EndIf
WEnd

_TimeKeyPressed

#include <IsPressed_UDF.au3>

; #Example# ===================================================================
; Name : _IsTimeKeyPressed
; Parameter(s) : Check "01" time down key (leftmouse)
; Author(s): FireFox
;===============================================================================

While 1
$key = _IsTimeKeyPressed("01")
If $key <> -1 Then TrayTip('_IsTimeKeyPressed', $key, 2, 4)
WEnd

IsPressed_UDF 2.3 : IsPressed_UDF.au3
IsPressed_UDF 2.2 : IsPressed_UDF.au3

Add IsPressed_UDF functions to SciTE : IsPressed_Function

Enjoy !
:)

Edited by FireFox
Link to comment
Share on other sites

You could use another func for that '_GetKeyByHex' or something, just replace the params :)

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Instead of using ...

If $sHexKey = "01" Then Return "LeftMouse"
    If $sHexKey = "02" Then Return "RightMouse"
    If $sHexKey = "04" Then Return "MiddleMouse"
    If $sHexKey = "05" Then Return "X1Mouse"
    If $sHexKey = "06" Then Return "X2Mouse"
    If $sHexKey = "08" Then Return "BACKSPACE"
    If $sHexKey = "09" Then Return "TAB"

Do a Switch command. They're much faster for these types of statements.

and .. I may be wrong on this, but theoretically if you would convert $sHexKey to a number first, and compare it to other numbers, it would be much faster. ( Numbers compare faster than strings.)

Also, thanks for mentioning my name for something that unimportant.

Edited by Manadar
Link to comment
Share on other sites

Instead of using ...

If $sHexKey = "01" Then Return "LeftMouse"
    If $sHexKey = "02" Then Return "RightMouse"
    If $sHexKey = "04" Then Return "MiddleMouse"
    If $sHexKey = "05" Then Return "X1Mouse"
    If $sHexKey = "06" Then Return "X2Mouse"
    If $sHexKey = "08" Then Return "BACKSPACE"
    If $sHexKey = "09" Then Return "TAB"

Do a Switch command. They're much faster for these types of statements.

and .. I may be wrong on this, but theoretically if you would convert $sHexKey to a number first, and compare it to other numbers, it would be much faster. ( Numbers compare faster than strings.)

Examples are welcome !

Also, thanks for mentioning my name for something that unimportant.

No problem :)
Link to comment
Share on other sites

Examples are welcome !

I thought you were going to say that... 8)

[autoit]; Generates a bunch of random numbers to perform the tests with

Dim $numtest = 100000

Dim $random[$numtest]

ConsoleWrite("Generating random numbers.. ")

For $i = 0 to $numtest-1

$random[$i] = Random(1, Dec("A5"),1)

Next

ConsoleWrite("Done." & @CRLF)

ConsoleWrite("Doing test A.. ")

$testAStart = TimerInit()

For $i = 0 to $numtest-1

_GetKeyByHex_Original($random[$i])

Next

$testAFinish = TimerDiff($testAStart)

ConsoleWrite("Done." & @CRLF)

ConsoleWrite("Doing test B.. ")

$testBStart = TimerInit()

For $i = 0 to $numtest-1

_GetKeyByHex_Original($random[$i])

Next

$testBFinish = TimerDiff($testBStart)

ConsoleWrite("Done." & @CRLF & @CRLF)

ConsoleWrite("Results:" & @CRLF)

ConsoleWrite("Test A: " & $testAFinish & @CRLF)

ConsoleWrite("Test B: " & $testBFinish & @CRLF)

; #FUNCTION# ===================================================================

; Name : _GetKeyByHex

; Description: Returns Alpha key for specified Hexadecimal key

; Parameter(s): None

; Requirement(s): None

; Return Value(s): On Success - Returns Aplha Key

; On Failure - Returns -1

; Author(s): FireFox

; Note(s): Thanks to AlmarM for idea

;===============================================================================

Func _GetKeyByHex_Original($sHexKey)

If $sHexKey = "01" Then Return "LeftMouse"

If $sHexKey = "02" Then Return "RightMouse"

If $sHexKey = "04" Then Return "MiddleMouse"

If $sHexKey = "05" Then Return "X1Mouse"

If $sHexKey = "06" Then Return "X2Mouse"

If $sHexKey = "08" Then Return "BACKSPACE"

If $sHexKey = "09" Then Return "TAB"

If $sHexKey = "0C" Then Return "CLEAR"

If $sHexKey = "0D" Then Return "ENTER"

If $sHexKey = "10" Then Return "SHIFT"

If $sHexKey = "11" Then Return "CTRL"

If $sHexKey = "12" Then Return "ALT"

If $sHexKey = "13" Then Return "PAUSE"

If $sHexKey = "14" Then Return "CAPSLOCK"

If $sHexKey = "1B" Then Return "ESC"

If $sHexKey = "20" Then Return "SPACEBAR"

If $sHexKey = "21" Then Return "PAGE UP"

If $sHexKey = "22" Then Return "PAGE DOWN"

If $sHexKey = "23" Then Return "END"

If $sHexKey = "24" Then Return "HOME"

If $sHexKey = "25" Then Return "LEFT"

If $sHexKey = "26" Then Return "UP"

If $sHexKey = "27" Then Return "RIGHT"

If $sHexKey = "28" Then Return "DOWN"

If $sHexKey = "29" Then Return "SELECT"

If $sHexKey = "2A" Then Return "PRINT"

If $sHexKey = "2B" Then Return "EXECUTE"

If $sHexKey = "2C" Then Return "PRINT SCREEN"

If $sHexKey = "2D" Then Return "INS"

If $sHexKey = "2E" Then Return "DEL"

If $sHexKey = "30" Then Return "0"

If $sHexKey = "31" Then Return "1"

If $sHexKey = "32" Then Return "2"

If $sHexKey = "33" Then Return "3"

If $sHexKey = "34" Then Return "4"

If $sHexKey = "35" Then Return "5"

If $sHexKey = "36" Then Return "6"

If $sHexKey = "37" Then Return "7"

If $sHexKey = "38" Then Return "8"

If $sHexKey = "39" Then Return "9"

If $sHexKey = "41" Then Return "A"

If $sHexKey = "42" Then Return "B"

If $sHexKey = "43" Then Return "C"

If $sHexKey = "44" Then Return "D"

If $sHexKey = "45" Then Return "E"

If $sHexKey = "46" Then Return "F"

If $sHexKey = "47" Then Return "G"

If $sHexKey = "48" Then Return "H"

If $sHexKey = "49" Then Return "I"

If $sHexKey = "4A" Then Return "J"

If $sHexKey = "4B" Then Return "K"

If $sHexKey = "4C" Then Return "L"

If $sHexKey = "4D" Then Return "M"

If $sHexKey = "4E" Then Return "N"

If $sHexKey = "4F" Then Return "O"

If $sHexKey = "50" Then Return "P"

If $sHexKey = "51" Then Return "Q"

If $sHexKey = "52" Then Return "R"

If $sHexKey = "53" Then Return "S"

If $sHexKey = "54" Then Return "T"

If $sHexKey = "55" Then Return "U"

If $sHexKey = "56" Then Return "V"

If $sHexKey = "57" Then Return "W"

If $sHexKey = "58" Then Return "X"

If $sHexKey = "59" Then Return "Y"

If $sHexKey = "5A" Then Return "Z"

If $sHexKey = "5B" Then Return "LWin"

If $sHexKey = "5C" Then Return "RWin"

If $sHexKey = "60" Then Return "0'"

If $sHexKey = "61" Then Return "1'"

If $sHexKey = "62" Then Return "2'"

If $sHexKey = "63" Then Return "3'"

If $sHexKey = "64" Then Return "4'"

If $sHexKey = "65" Then Return "5'"

If $sHexKey = "66" Then Return "6'"

If $sHexKey = "67" Then Return "7'"

If $sHexKey = "68" Then Return "8'"

If $sHexKey = "69" Then Return "9'"

If $sHexKey = "6A" Then Return "Multiply"

If $sHexKey = "6B" Then Return "Add"

If $sHexKey = "6C" Then Return "Separator"

If $sHexKey = "6D" Then Return "Subtract"

If $sHexKey = "6E" Then Return "Decimal"

If $sHexKey = "6F" Then Return "Divide"

If $sHexKey = "70" Then Return "F1"

If $sHexKey = "71" Then Return "F2"

If $sHexKey = "72" Then Return "F3"

If $sHexKey = "73" Then Return "F4"

If $sHexKey = "74" Then Return "F5"

If $sHexKey = "75" Then Return "F6"

If $sHexKey = "76" Then Return "F7"

If $sHexKey = "77" Then Return "F8"

If $sHexKey = "78" Then Return "F9"

If $sHexKey = "79" Then Return "F10"

If $sHexKey = "7A" Then Return "F11"

If $sHexKey = "7B" Then Return "F12"

If $sHexKey = "7C" Then Return "F13"

If $sHexKey = "7F" Then Return "F16"

If $sHexKey = "80H" Then Return "F17"

If $sHexKey = "87H" Then Return "F24"

If $sHexKey = "90" Then Return "NUM LOCK"

If $sHexKey = "91" Then Return "SCROLL LOCK"

If $sHexKey = "A0" Then Return "LSHIFT"

If $sHexKey = "A1" Then Return "RSHIFT"

If $sHexKey = "A2" Then Return "LCTRL"

If $sHexKey = "A3" Then Return "RCTRL"

If $sHexKey = "A4" Then Return "LMENU"

If $sHexKey = "A5" Then Return "RMENU"

If $sHexKey = "" Then Return -1

Return -1

EndFunc ;==>_GetKeyByHex_Original

Func _GetKeyByHex_Switch($sHexKey)

Switch $sHexKey

Case "01"

Return "LeftMouse"

Case "02"

Return "RightMouse"

Case "04"

Return "MiddleMouse"

Case "05"

Return "X1Mouse"

Case "06"

Return "X2Mouse"

Case "08"

Return "BACKSPACE"

Case "09"

Return "TAB"

Case "0C"

Return "CLEAR"

Case "0D"

Return "ENTER"

Case "10"

Return "SHIFT"

Case "11"

Return "CTRL"

Case "12"

Return "ALT"

Case "13"

Return "PAUSE"

Case "14"

Return "CAPSLOCK"

Case "1B"

Return "ESC"

Case "20"

Return "SPACEBAR"

Case "21"

Return "PAGE UP"

Case "22"

Return "PAGE DOWN"

Case "23"

Return "END"

Case "24"

Return "HOME"

Case "25"

Return "LEFT"

Case "26"

Return "UP"

Case "27"

Return "RIGHT"

Case "28"

Return "DOWN"

Case "29"

Return "SELECT"

Case "2A"

Return "PRINT"

Case "2B"

Return "EXECUTE"

Case "2C"

Return "PRINT SCREEN"

Case "2D"

Return "INS"

Case "2E"

Return "DEL"

Case "30"

Return "0"

Case "31"

Return "1"

Case "32"

Return "2"

Case "33"

Return "3"

Case "34"

Return "4"

Case "35"

Return "5"

Case "36"

Return "6"

Case "37"

Return "7"

Case "38"

Return "8"

Case "39"

Return "9"

Case "41"

Return "A"

Case "42"

Return "B"

Case "43"

Return "C"

Case "44"

Return "D"

Case "45"

Return "E"

Case "46"

Return "F"

Case "47"

Return "G"

Case "48"

Return "H"

Case "49"

Return "I"

Case "4A"

Return "J"

Case "4B"

Return "K"

Case "4C"

Return "L"

Case "4D"

Return "M"

Case "4E"

Return "N"

Case "4F"

Return "O"

Case "50"

Return "P"

Case "51"

Return "Q"

Case "52"

Return "R"

Case "53"

Return "S"

Case "54"

Return "T"

Case "55"

Return "U"

Case "56"

Return "V"

Case "57"

Return "W"

Case "58"

Return "X"

Case "59"

Return "Y"

Case "5A"

Return "Z"

Case "5B"

Return "LWin"

Case "5C"

Return "RWin"

Case "60"

Return "0'"

Case "61"

Return "1'"

Case "62"

Return "2'"

Case "63"

Return "3'"

Case "64"

Return "4'"

Case "65"

Return "5'"

Case "66"

Return "6'"

Case "67"

Return "7'"

Case "68"

Return "8'"

Case "69"

Return "9'"

Case "6A"

Return "Multiply"

Case "6B"

Return "Add"

Case "6C"

Return "Separator"

Case "6D"

Return "Subtract"

Case "6E"

Return "Decimal"

Case "6F"

Return "Divide"

Case "70"

Return "F1"

Case "71"

Return "F2"

Case "72"

Return "F3"

Case "73"

Return "F4"

Case "74"

Return "F5"

Case "75"

Return "F6"

Case "76"

Return "F7"

Case "77"

Return "F8"

Case "78"

Return "F9"

Case "79"

Return "F10"

Case "7A"

Return "F11"

Case "7B"

Return "F12"

Case "7C"

Return "F13"

Case "7F"

Return "F16"

Case "80H"

Return "F17"

Case "87H"

Return "F24"

Case "90"

Return "NUM LOCK"

Case "91"

Return "SCROLL LOCK"

Case "A0"

Return "LSHIFT"

Case "A1"

Return "RSHIFT"

Case "A2"

Return "LCTRL"

Case "A3"

Return "RCTRL"

Case "A4"

Return "LMENU"

Case "A5"

Return "RMENU"

EndSwitch

Return -1

EndFunc ;==>_GetKeyByHex_Switch

Edited by Manadar
Link to comment
Share on other sites

Maybe....

; #FUNCTION# ===================================================================
; Name :             _GetKeyByHex
; Description:      Returns Alpha key for specified Hexadecimal key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Aplha Key
;                   On Failure - Returns -1
; Author(s):        FireFox
; Note(s):            Thanks to AlmarM for idea
;===============================================================================
Func _GetKeyByHex($sHexKey)
    Return __GetKeyType($sHexKey)
EndFunc   ;==>_GetKeyByHex

; #FUNCTION# ===================================================================
; Name :             _GetKeyByAlpha
; Description:      Returns Hexadecimal key for specified Alpha key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Hexadecimal Key
;                   On Failure - Returns 0
; Author(s):        FireFox
; Note(s):            Thanks to AlmarM for idea
;===============================================================================
Func _GetKeyByAlpha($sAlphaKey)
    Return __GetKeyType($sAlphaKey, 1)
EndFunc   ;==>_GetKeyByAlpha


Func __GetKeyType($iKeyIn, $iType = -1)
    
    If $iKeyIn = "" Then Return -1
    
    Local $ikey, $hKey = "01,02,04,05,06" & _
            "continued" ; example
    Local $nKey = "LeftMouse,RightMouse,MiddleMouse,X1Mouse,X2Mouse" & _
            "continued" ; example
    
    $hKey = StringSplit($hKey, ",")
    $nKey = StringSplit($nKey, ",")

    For $ikey = 1 To $hKey[0]
        If $iType == -1 And $iKeyIn = $hKey[$ikey] Then Return $nKey[$ikey]
        If $iType <> -1 And $iKeyIn = $nKey[$ikey] Then Return $hKey[$ikey]
    Next
    
    Return -1
EndFunc   ;==>__GetKeyType

if it is speed you want, this can be split into 2 different loops

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

@Manadar

Thanks for your example

Generating random numbers.. Done.
   Doing test A.. Done.
   Doing test B.. Done.
   
   Results:
   Test A: 10789.901169566
   Test B: 10782.8232672745

Seems to be almost same speed on my computer :)

@Valuater

Thanks too for your example I think I will add it to udf :o

Edited by FireFox
Link to comment
Share on other sites

@Manadar

"Right CTRL, Left MENU,Right Menu"

Thanks, I will fix it :)

Also, use proper (consistent) capitalizing.

??

Don't think I'm nitpicking, I want this to be the best it can.

Thanks for your support i agree with you dont worry :o
Link to comment
Share on other sites

I actualy tried it with a 'Select, Case'... Results are dramatic :P

; Generates a bunch of random numbers to perform the tests with

Dim $numtest = 100000

Dim $random[$numtest]

ConsoleWrite("Generating random numbers.. ")

For $i = 0 to $numtest-1
    $random[$i] = Random(1, Dec("A5"),1)
Next

ConsoleWrite("Done." & @CRLF)

ConsoleWrite("Doing test A.. ")

$testAStart = TimerInit()
For $i = 0 to $numtest-1
    _GetKeyByHex_Original($random[$i])
Next
$testAFinish = TimerDiff($testAStart)

ConsoleWrite("Done." & @CRLF)

ConsoleWrite("Doing test B.. ")

$testBStart = TimerInit()
For $i = 0 to $numtest-1
    _GetKeyByHex_Original($random[$i])
Next
$testBFinish = TimerDiff($testBStart)

ConsoleWrite("Done." & @CRLF)

ConsoleWrite("Doing test C.. ")

$testCStart = TimerInit()
For $i = 0 to $numtest-1
    _GetKeyByHex_Select($random[$i])
Next
$testCFinish = TimerDiff($testCStart)

ConsoleWrite("Done." & @CRLF & @CRLF)

ConsoleWrite("Results:" & @CRLF)

ConsoleWrite("Test A: " & $testAFinish & @CRLF)
ConsoleWrite("Test B: " & $testBFinish & @CRLF)
ConsoleWrite("Test C: " & $testCFinish & @CRLF)


; #FUNCTION# ===================================================================
; Name :             _GetKeyByHex
; Description:      Returns Alpha key for specified Hexadecimal key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Aplha Key
;                   On Failure - Returns -1
; Author(s):        FireFox
; Note(s):      Thanks to AlmarM for idea
;===============================================================================

Func _GetKeyByHex_Select($sHexKey)
    Select
    Case StringInStr("01", $sHexKey)
        Return "LeftMouse"
    Case StringInStr("02", $sHexKey)
        Return "RightMouse"
    Case StringInStr("04", $sHexKey)
        Return "MiddleMouse"
    Case StringInStr("05", $sHexKey)
        Return "X1Mouse"
    Case StringInStr("06", $sHexKey)
        Return "X2Mouse"
    Case StringInStr("08", $sHexKey)
        Return "BACKSPACE"
    Case StringInStr("09", $sHexKey)
        Return "TAB"
    Case StringInStr("0C", $sHexKey)
        Return "CLEAR"
    Case StringInStr("0D", $sHexKey)
        Return "ENTER"
    Case StringInStr("10", $sHexKey)
        Return "SHIFT"
    Case StringInStr("11", $sHexKey)
        Return "CTRL"
    Case StringInStr("12", $sHexKey)
        Return "ALT"
    Case StringInStr("13", $sHexKey)
        Return "PAUSE"
    Case StringInStr("14", $sHexKey)
        Return "CAPSLOCK"
    Case StringInStr("1B", $sHexKey)
        Return "ESC"
    Case StringInStr("20", $sHexKey)
        Return "SPACEBAR"
    Case StringInStr("21", $sHexKey)
        Return "PAGE UP"
    Case StringInStr("22", $sHexKey)
        Return "PAGE DOWN"
    Case StringInStr("23", $sHexKey)
        Return "END"
    Case StringInStr("24", $sHexKey)
        Return "HOME"
    Case StringInStr("25", $sHexKey)
        Return "LEFT"
    Case StringInStr("26", $sHexKey)
        Return "UP"
    Case StringInStr("27", $sHexKey)
        Return "RIGHT"
    Case StringInStr("28", $sHexKey)
        Return "DOWN"
    Case StringInStr("29", $sHexKey)
        Return "SELECT"
    Case StringInStr("2A", $sHexKey)
        Return "PRINT"
    Case StringInStr("2B", $sHexKey)
        Return "EXECUTE"
    Case StringInStr("2C", $sHexKey)
        Return "PRINT SCREEN"
    Case StringInStr("2D", $sHexKey)
        Return "INS"
    Case StringInStr("2E", $sHexKey)
        Return "DEL"
    Case StringInStr("30", $sHexKey)
        Return "0"
    Case StringInStr("31", $sHexKey)
        Return "1"
    Case StringInStr("32", $sHexKey)
        Return "2"
    Case StringInStr("33", $sHexKey)
        Return "3"
    Case StringInStr("34", $sHexKey)
        Return "4"
    Case StringInStr("35", $sHexKey)
        Return "5"
    Case StringInStr("36", $sHexKey)
        Return "6"
    Case StringInStr("37", $sHexKey)
        Return "7"
    Case StringInStr("38", $sHexKey)
        Return "8"
    Case StringInStr("39", $sHexKey)
        Return "9"
    Case StringInStr("41", $sHexKey)
        Return "A"
    Case StringInStr("42", $sHexKey)
        Return "B"
    Case StringInStr("43", $sHexKey)
        Return "C"
    Case StringInStr("44", $sHexKey)
        Return "D"
    Case StringInStr("45", $sHexKey)
        Return "E"
    Case StringInStr("46", $sHexKey)
        Return "F"
    Case StringInStr("47", $sHexKey)
        Return "G"
    Case StringInStr("48", $sHexKey)
        Return "H"
    Case StringInStr("49", $sHexKey)
        Return "I"
    Case StringInStr("4A", $sHexKey)
        Return "J"
    Case StringInStr("4B", $sHexKey)
        Return "K"
    Case StringInStr("4C", $sHexKey)
        Return "L"
    Case StringInStr("4D", $sHexKey)
        Return "M"
    Case StringInStr("4E", $sHexKey)
        Return "N"
    Case StringInStr("4F", $sHexKey)
        Return "O"
    Case StringInStr("50", $sHexKey)
        Return "P"
    Case StringInStr("51", $sHexKey)
        Return "Q"
    Case StringInStr("52", $sHexKey)
        Return "R"
    Case StringInStr("53", $sHexKey)
        Return "S"
    Case StringInStr("54", $sHexKey)
        Return "T"
    Case StringInStr("55", $sHexKey)
        Return "U"
    Case StringInStr("56", $sHexKey)
        Return "V"
    Case StringInStr("57", $sHexKey)
        Return "W"
    Case StringInStr("58", $sHexKey)
        Return "X"
    Case StringInStr("59", $sHexKey)
        Return "Y"
    Case StringInStr("5A", $sHexKey)
        Return "Z"
    Case StringInStr("5B", $sHexKey)
        Return "LWin"
    Case StringInStr("5C", $sHexKey)
        Return "RWin"
    Case StringInStr("60", $sHexKey)
        Return "0'"
    Case StringInStr("61", $sHexKey)
        Return "1'"
    Case StringInStr("62", $sHexKey)
        Return "2'"
    Case StringInStr("63", $sHexKey)
        Return "3'"
    Case StringInStr("64", $sHexKey)
        Return "4'"
    Case StringInStr("65", $sHexKey)
        Return "5'"
    Case StringInStr("66", $sHexKey)
        Return "6'"
    Case StringInStr("67", $sHexKey)
        Return "7'"
    Case StringInStr("68", $sHexKey)
        Return "8'"
    Case StringInStr("69", $sHexKey)
        Return "9'"
    Case StringInStr("6A", $sHexKey)
        Return "Multiply"
    Case StringInStr("6B", $sHexKey)
        Return "Add"
    Case StringInStr("6C", $sHexKey)
        Return "Separator"
    Case StringInStr("6D", $sHexKey)
        Return "Substract"
    Case StringInStr("6E", $sHexKey)
        Return "Decimal"
    Case StringInStr("6F", $sHexKey)
        Return "Devide"
    Case StringInStr("70", $sHexKey)
        Return "F1"
    Case StringInStr("71", $sHexKey)
        Return "F2"
    Case StringInStr("72", $sHexKey)
        Return "F3"
    Case StringInStr("73", $sHexKey)
        Return "F4"
    Case StringInStr("74", $sHexKey)
        Return "F5"
    Case StringInStr("75", $sHexKey)
        Return "F6"
    Case StringInStr("76", $sHexKey)
        Return "F7"
    Case StringInStr("77", $sHexKey)
        Return "F8"
    Case StringInStr("78", $sHexKey)
        Return "F9"
    Case StringInStr("79", $sHexKey)
        Return "F10"
    Case StringInStr("7A", $sHexKey)
        Return "F11"
    Case StringInStr("7B", $sHexKey)
        Return "F12"
    Case StringInStr("7C", $sHexKey)
        Return "F13"
    Case StringInStr("7F", $sHexKey)
        Return "F16"
    Case StringInStr("90", $sHexKey)
        Return "NUM LOCK"
    Case StringInStr("91", $sHexKey)
        Return "SCROLL LOCK"
    Case StringInStr("A0", $sHexKey)
        Return "LSHIFT"
    Case StringInStr("A1", $sHexKey)
        Return "RSHIFT"
    Case StringInStr("A2", $sHexKey)
        Return "LCTRL"
    Case StringInStr("A3", $sHexKey)
        Return "RCTRL"
    Case StringInStr("A4", $sHexKey)
        Return "LMENU"
    Case StringInStr("A5", $sHexKey)
        Return "RMENU"
    Case StringInStr("", $sHexKey)
        Return -1
    EndSelect
EndFunc     ;==>_GetKeyByHex_Select

Func _GetKeyByHex_Original($sHexKey)
    If $sHexKey = "01" Then Return "LeftMouse"
    If $sHexKey = "02" Then Return "RightMouse"
    If $sHexKey = "04" Then Return "MiddleMouse"
    If $sHexKey = "05" Then Return "X1Mouse"
    If $sHexKey = "06" Then Return "X2Mouse"
    If $sHexKey = "08" Then Return "BACKSPACE"
    If $sHexKey = "09" Then Return "TAB"
    If $sHexKey = "0C" Then Return "CLEAR"
    If $sHexKey = "0D" Then Return "ENTER"
    If $sHexKey = "10" Then Return "SHIFT"
    If $sHexKey = "11" Then Return "CTRL"
    If $sHexKey = "12" Then Return "ALT"
    If $sHexKey = "13" Then Return "PAUSE"
    If $sHexKey = "14" Then Return "CAPSLOCK"
    If $sHexKey = "1B" Then Return "ESC"
    If $sHexKey = "20" Then Return "SPACEBAR"
    If $sHexKey = "21" Then Return "PAGE UP"
    If $sHexKey = "22" Then Return "PAGE DOWN"
    If $sHexKey = "23" Then Return "END"
    If $sHexKey = "24" Then Return "HOME"
    If $sHexKey = "25" Then Return "LEFT"
    If $sHexKey = "26" Then Return "UP"
    If $sHexKey = "27" Then Return "RIGHT"
    If $sHexKey = "28" Then Return "DOWN"
    If $sHexKey = "29" Then Return "SELECT"
    If $sHexKey = "2A" Then Return "PRINT"
    If $sHexKey = "2B" Then Return "EXECUTE"
    If $sHexKey = "2C" Then Return "PRINT SCREEN"
    If $sHexKey = "2D" Then Return "INS"
    If $sHexKey = "2E" Then Return "DEL"
    If $sHexKey = "30" Then Return "0"
    If $sHexKey = "31" Then Return "1"
    If $sHexKey = "32" Then Return "2"
    If $sHexKey = "33" Then Return "3"
    If $sHexKey = "34" Then Return "4"
    If $sHexKey = "35" Then Return "5"
    If $sHexKey = "36" Then Return "6"
    If $sHexKey = "37" Then Return "7"
    If $sHexKey = "38" Then Return "8"
    If $sHexKey = "39" Then Return "9"
    If $sHexKey = "41" Then Return "A"
    If $sHexKey = "42" Then Return "B"
    If $sHexKey = "43" Then Return "C"
    If $sHexKey = "44" Then Return "D"
    If $sHexKey = "45" Then Return "E"
    If $sHexKey = "46" Then Return "F"
    If $sHexKey = "47" Then Return "G"
    If $sHexKey = "48" Then Return "H"
    If $sHexKey = "49" Then Return "I"
    If $sHexKey = "4A" Then Return "J"
    If $sHexKey = "4B" Then Return "K"
    If $sHexKey = "4C" Then Return "L"
    If $sHexKey = "4D" Then Return "M"
    If $sHexKey = "4E" Then Return "N"
    If $sHexKey = "4F" Then Return "O"
    If $sHexKey = "50" Then Return "P"
    If $sHexKey = "51" Then Return "Q"
    If $sHexKey = "52" Then Return "R"
    If $sHexKey = "53" Then Return "S"
    If $sHexKey = "54" Then Return "T"
    If $sHexKey = "55" Then Return "U"
    If $sHexKey = "56" Then Return "V"
    If $sHexKey = "57" Then Return "W"
    If $sHexKey = "58" Then Return "X"
    If $sHexKey = "59" Then Return "Y"
    If $sHexKey = "5A" Then Return "Z"
    If $sHexKey = "5B" Then Return "LWin"
    If $sHexKey = "5C" Then Return "RWin"
    If $sHexKey = "60" Then Return "0'"
    If $sHexKey = "61" Then Return "1'"
    If $sHexKey = "62" Then Return "2'"
    If $sHexKey = "63" Then Return "3'"
    If $sHexKey = "64" Then Return "4'"
    If $sHexKey = "65" Then Return "5'"
    If $sHexKey = "66" Then Return "6'"
    If $sHexKey = "67" Then Return "7'"
    If $sHexKey = "68" Then Return "8'"
    If $sHexKey = "69" Then Return "9'"
    If $sHexKey = "6A" Then Return "Multiply"
    If $sHexKey = "6B" Then Return "Add"
    If $sHexKey = "6C" Then Return "Separator"
    If $sHexKey = "6D" Then Return "Subtract"
    If $sHexKey = "6E" Then Return "Decimal"
    If $sHexKey = "6F" Then Return "Divide"
    If $sHexKey = "70" Then Return "F1"
    If $sHexKey = "71" Then Return "F2"
    If $sHexKey = "72" Then Return "F3"
    If $sHexKey = "73" Then Return "F4"
    If $sHexKey = "74" Then Return "F5"
    If $sHexKey = "75" Then Return "F6"
    If $sHexKey = "76" Then Return "F7"
    If $sHexKey = "77" Then Return "F8"
    If $sHexKey = "78" Then Return "F9"
    If $sHexKey = "79" Then Return "F10"
    If $sHexKey = "7A" Then Return "F11"
    If $sHexKey = "7B" Then Return "F12"
    If $sHexKey = "7C" Then Return "F13"
    If $sHexKey = "7F" Then Return "F16"
    If $sHexKey = "90" Then Return "NUM LOCK"
    If $sHexKey = "91" Then Return "SCROLL LOCK"
    If $sHexKey = "A0" Then Return "LSHIFT"
    If $sHexKey = "A1" Then Return "RSHIFT"
    If $sHexKey = "A2" Then Return "LCTRL"
    If $sHexKey = "A3" Then Return "RCTRL"
    If $sHexKey = "A4" Then Return "LMENU"
    If $sHexKey = "A5" Then Return "RMENU"
    If $sHexKey = "" Then Return -1
    Return -1
EndFunc   ;==>_GetKeyByHex_Original

Func _GetKeyByHex_SwitchNumber($sHexKey)
    $sHexKey = Dec($sHexKey)
    Switch $sHexKey
        Case 1
            Return "LeftMouse"
        Case 2
            Return "RightMouse"
        Case 4
            Return "MiddleMouse"
        Case 5
            Return "X1Mouse"
        Case 6
            Return "X2Mouse"
        Case 8
            Return "BACKSPACE"
        Case 9
            Return "TAB"
        Case 12
            Return "CLEAR"
        Case 13
            Return "ENTER"
        Case 16
            Return "SHIFT"
        Case 17
            Return "CTRL"
        Case 18
            Return "ALT"
        Case 19
            Return "PAUSE"
        Case 20
            Return "CAPSLOCK"
        Case 27
            Return "ESC"
        Case 32
            Return "SPACEBAR"
        Case 33
            Return "PAGE UP"
        Case 34
            Return "PAGE DOWN"
        Case 35
            Return "END"
        Case 36
            Return "HOME"
        Case 37
            Return "LEFT"
        Case 38
            Return "UP"
        Case 39
            Return "RIGHT"
        Case 40
            Return "DOWN"
        Case 41
            Return "SELECT"
        Case 42
            Return "PRINT"
        Case 43
            Return "EXECUTE"
        Case 44
            Return "PRINT SCREEN"
        Case 45
            Return "INS"
        Case 46
            Return "DEL"
        Case 48
            Return "0"
        Case 49
            Return "1"
        Case 50
            Return "2"
        Case 51
            Return "3"
        Case 52
            Return "4"
        Case 53
            Return "5"
        Case 54
            Return "6"
        Case 55
            Return "7"
        Case 56
            Return "8"
        Case 57
            Return "9"
        Case 65
            Return "A"
        Case 66
            Return "B"
        Case 67
            Return "C"
        Case 68
            Return "D"
        Case 69
            Return "E"
        Case 70
            Return "F"
        Case 71
            Return "G"
        Case 72
            Return "H"
        Case 73
            Return "I"
        Case 74
            Return "J"
        Case 75
            Return "K"
        Case 76
            Return "L"
        Case 77
            Return "M"
        Case 78
            Return "N"
        Case 79
            Return "O"
        Case 80
            Return "P"
        Case 81
            Return "Q"
        Case 82
            Return "R"
        Case 83
            Return "S"
        Case 84
            Return "T"
        Case 85
            Return "U"
        Case 86
            Return "V"
        Case 87
            Return "W"
        Case 88
            Return "X"
        Case 89
            Return "Y"
        Case 90
            Return "Z"
        Case 91
            Return "LWin"
        Case 92
            Return "RWin"
        Case 96
            Return "0'"
        Case 97
            Return "1'"
        Case 98
            Return "2'"
        Case 99
            Return "3'"
        Case 100
            Return "4'"
        Case 101
            Return "5'"
        Case 102
            Return "6'"
        Case 103
            Return "7'"
        Case 104
            Return "8'"
        Case 105
            Return "9'"
        Case 106
            Return "Multiply"
        Case 107
            Return "Add"
        Case 108
            Return "Separator"
        Case 109
            Return "Subtract"
        Case 110
            Return "Decimal"
        Case 111
            Return "Divide"
        Case 112
            Return "F1"
        Case 113
            Return "F2"
        Case 114
            Return "F3"
        Case 115
            Return "F4"
        Case 116
            Return "F5"
        Case 117
            Return "F6"
        Case 118
            Return "F7"
        Case 119
            Return "F8"
        Case 120
            Return "F9"
        Case 121
            Return "F10"
        Case 122
            Return "F11"
        Case 123
            Return "F12"
        Case 124
            Return "F13"
        Case 127
            Return "F16"
        Case 144
            Return "NUM LOCK"
        Case 145
            Return "SCROLL LOCK"
        Case 160
            Return "LSHIFT"
        Case 161
            Return "RSHIFT"
        Case 162
            Return "LCTRL"
        Case 163
            Return "RCTRL"
        Case 164
            Return "LMENU"
        Case 165
            Return "RMENU"
    EndSwitch
    Return -1
EndFunc   ;==>_GetKeyByHex_Switch

Result

Generating random numbers.. Done.
Doing test A.. Done.
Doing test B.. Done.
Doing test C.. Done.

Results:
Test A: 20308.6193915707
Test B: 18904.5141212081
Test C: 25406.7145405352

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
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
 Share

×
×
  • Create New...