Jump to content

IsPressed_UDF ! v2.3 | Advanced keypress


FireFox
 Share

Recommended Posts

I take it we all know you mean't --> _IsWheelKeyScroll

:blink:

"5C" (RIGHT WINDOWS) does not work on my computer (XP Pro, french keyboard AZERTY)

Sample :

HotKeySet("5C", "My_Function_Exit")

Why ?

Thanks for your help.

Edited by ldub
Link to comment
Share on other sites

"5C" (RIGHT WINDOWS) does not work on my computer (XP Pro, french keyboard AZERTY)

Sample :

HotKeySet("5C", "My_Function_Exit")

Why ?

Thanks for your help.

You're wrong, look at the helpfile for Send

HotKeySet("{RWINDOWN}", "My_Function_Exit")

While Sleep(250)
    If _IsPressed("5C") Then
        ;do stuff
    EndIf
WEnd

Please ask those questions on the right forum for the next time Posted Image

FireFox.

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

Here's a snipit that captures the scroll direction (not related to _ispressed in any way)

Global $mouseEvent=0
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", 14, "ptr", DllCallbackGetPtr(DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")), "hwnd", $hM_Module[0], "dword", 0)

While 1
If $mouseEvent = 120 Then
        MsgBox(0,"Mouse Event", "Mouse was scrolled up")
        $mouseEvent=0
    EndIf

    If $mouseEvent = -120 Then
        MsgBox(0,"Mouse Event", "Mouse was scrolled down")
        $mouseEvent=0
    EndIf
Sleep(10)
WEnd

Func _Mouse_Proc($nCode, $wParam, $lParam)
    $mouseData = DllStructGetData(DllStructCreate("int X;int Y" & ";dword mouseData", $lParam), 3)
    If $wParam = 0x020A Then $mouseEvent = BitShift($mouseData, 16)
EndFunc   ;==>_Mouse_Proc
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • 4 weeks later...

This is great!

I've idea for new function:

_IsTimeBetweenKeysPressed

What is it?

Time: Event:

00:01 I press key "X"

00:02 I stop // _IsTimeKeyPressed returns 1000 ms

// Time between first and second pressing

00:05 I press key "Y"

00:07 I stop // _IsTimeKeyPressed returns 2000 ms

_IsTimeBetweenKeysPressed returns 3000 ms

Link to comment
Share on other sites

This is great!

I've idea for new function:

Give your idea then :x

_IsTimeKeyPressed function returns the pressed time of specified key (read the description)

e.g : if you want to check the pressed time of right click then

;you press rightclick
MsgBox(64, "", _IsTimeKeyPressed('01')) ; the msgbox will show when the right click will be released
;it will return in ms the elapsed time between the function call and the release of the key.

Br, FireFox.

Link to comment
Share on other sites

_IsTimeKeyPressed function returns the pressed time of specified key (read the description)

The name of that function (compared to the others) tells me to go look for a Time key on my keyboard...

Not surprisingly, I do not find a Time key... :x

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

  • 5 months later...
  • 2 weeks later...

Hey, I just want to come back to your performance tuning of _GetKeyByHex_SwitchNumber... I optimized it to double speed (maybe a bit more possible).

I just cut the test-Switch-Statements into smaller slices (Test-blocks) being tested seperately in smaller Switch-Statements. This can be done one or two steps of smaller slices further to get a few more millis out of it. It's based on the idea to walk recursively through graph trees. Feel free to go this step further into the deep ;-)

Theoretically the most speed might be possible when comparing about 2 to 4 times in each nested Switch-block but I don't know AutoIts internal code optimization. This has to be given a try.

#Region short test
ConsoleWrite(@CRLF & "----------SHORT TEST----------")
Global $numtest = 10000
_Test()
#EndRegion short test

Func _longtest()
    #Region long test
    ConsoleWrite(@CRLF & @CRLF & "----------LONG TEST----------")
    Global $numtest = 300000
    _Test()
    #EndRegion long test
EndFunc   ;==>_longtest

Func _Test()
    #Region Number ------------------------------
    Local $random[$numtest]
    ConsoleWrite(@CRLF & "Generating random numbers...")

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

    ConsoleWrite("Done !" & @CRLF)
    #EndRegion Number ------------------------------

    #Region Test A ----------------------------------
    ConsoleWrite("Doing test A...")
    $testBStart = TimerInit()

    For $i = 0 To $numtest - 1
        _GetKeyByHex_SwitchNumber($random[$i])
    Next

    $testBFinish = StringLeft(TimerDiff($testBStart) * 0.001, 7)
    ConsoleWrite("Done ! " & "Result : " & $testBFinish & " sec(s)" & @CRLF)
    #EndRegion Test A ----------------------------------

    #Region Test B ----------------------------------
    ConsoleWrite("Doing test B...")
    $testBStart = TimerInit()

    For $i = 0 To $numtest - 1
        _GetKeyByHex_SwitchNumber_Samoth($random[$i])
    Next

    $testBFinish = StringLeft(TimerDiff($testBStart) * 0.001, 7)
    ConsoleWrite("Done ! " & "Result : " & $testBFinish & " sec(s)" & @CRLF)
    #EndRegion Test B ----------------------------------

    If $numtest = 300000 Then
        Exit
    Else
        _longtest()
    EndIf
EndFunc   ;==>_Test


; #FUNCTION# ===================================================================
; Name :               __GetKeyType
; Description:      Returns Hexadecimal or Aplha key for specified key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns 0
; Author(s):        Valuater, FireFox
; Note(s):          Thanks Valuater... 8)
;===============================================================================
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_SwitchNumber

; #FUNCTION# ===================================================================
; Name :               __GetKeyType
; Description:      Returns Hexadecimal or Aplha key for specified key
; Parameter(s):     HexKey
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns 0
; Author(s):        Samoth, Valuater, FireFox
; Note(s):          Thanks Valuater... 8)
;===============================================================================
Func _GetKeyByHex_SwitchNumber_Samoth($sHexKey)
    $sHexKey = Dec($sHexKey)
    Switch $sHexKey
        Case 1 To 37
            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"
            EndSwitch
        Case 38 To 68
            Switch $sHexKey
                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"
            EndSwitch
        Case 96 To 91
            Switch $sHexKey
                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"
            EndSwitch
        Case 92 To 115
            Switch $sHexKey
                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"
            EndSwitch
        Case 116 To 165
            Switch $sHexKey
                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
    EndSwitch
    Return -1
EndFunc   ;==>_GetKeyByHex_SwitchNumber
Edited by Samoth
Link to comment
Share on other sites

Sorry for double posting, but I can't edit my post any more??

I wrote a small new function based on array indexes getting its information from a pre-initialized in-memory static global array with blank entries. It's a fourth faster then my optimized version before... This version before can dynamically be optimized by a recursive function returning the code of the nested switch-Statements. But I won't bet it can get faster than this global array based method. And my new function is the shortest I've ever seen for this.

The default-Value 3 results in the first blank array entry, resulting in a return value of -1.

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\user\BWI\AutoIt\numbers.au3"    
LeftMouse
----------SHORT TEST----------
Generating random numbers...Done !
Doing test A...Done ! Result : 0.24911 sec(s)
Doing test B...Done ! Result : 0.12014 sec(s)
Doing test C...Done ! Result : 0.08559 sec(s)


----------LONG TEST----------
Generating random numbers...Done !
Doing test A...Done ! Result : 7.28746 sec(s)
Doing test B...Done ! Result : 3.76141 sec(s)
Doing test C...Done ! Result : 2.67726 sec(s)
>Exit code: 0    Time: 15.946

Global $a_Keys[165] = ["LeftMouse", "RightMouse", "", "MiddleMouse", "X1Mouse", "X2Mouse", "", _
    "BACKSPACE", "TAB", "", "", "CLEAR", "ENTER", "", "", "SHIFT", "CTRL", "ALT", "PAUSE", _
    "CAPSLOCK", "", "", "", "", "", "", "ESC", "", "", "", "", "SPACEBAR", "PAGE UP", "PAGE DOWN", _
    "END", "HOME", "LEFT", "UP", "RIGHT", "DOWN", "SELECT", "PRINT", "EXECUTE", "PRINT SCREEN", _
    "INS", "DEL", "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "", "", "", "", "", "", _
    "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", _
    "S", "T", "U", "V", "W", "X", "Y", "Z", "LWin", "RWin", "", "", "", "0'", "1'", "2'", "3'", _
    "4'", "5'", "6'", "7'", "8'", "9'", "Multiply", "Add", "Separator", "Subtract", "Decimal", _
    "Divide", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", _
    "", "", "F16", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "NUM LOCK", _
    "SCROLL LOCK", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "LSHIFT", "RSHIFT", _
    "LCTRL", "RCTRL", "LMENU", "RMENU"]

#Region short test
ConsoleWrite(@CRLF & "----------SHORT TEST----------")
Global $numtest = 10000
_Test()
#EndRegion short test

Func _longtest()
    #Region long test
    ConsoleWrite(@CRLF & @CRLF & "----------LONG TEST----------")
    Global $numtest = 300000
    _Test()
    #EndRegion long test
EndFunc   ;==>_longtest

Func _Test()
    #Region Number ------------------------------
    Local $random[$numtest]
    ConsoleWrite(@CRLF & "Generating random numbers...")

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

    ConsoleWrite("Done !" & @CRLF)
    #EndRegion Number ------------------------------

    #Region Test A ----------------------------------
    ConsoleWrite("Doing test A...")
    $testBStart = TimerInit()

    For $i = 0 To $numtest - 1
        _GetKeyByHex_SwitchNumber($random[$i])
    Next

    $testBFinish = StringLeft(TimerDiff($testBStart) * 0.001, 7)
    ConsoleWrite("Done ! " & "Result : " & $testBFinish & " sec(s)" & @CRLF)
    #EndRegion Test A ----------------------------------

    #Region Test B ----------------------------------
    ConsoleWrite("Doing test B...")
    $testBStart = TimerInit()

    For $i = 0 To $numtest - 1
        _GetKeyByHex_SwitchNumber_Samoth($random[$i])
    Next

    $testBFinish = StringLeft(TimerDiff($testBStart) * 0.001, 7)
    ConsoleWrite("Done ! " & "Result : " & $testBFinish & " sec(s)" & @CRLF)
    #EndRegion Test B ----------------------------------

    #Region Test C ------------------------------
    ConsoleWrite("Doing test C...")

    $testCStart = TimerInit()
    For $i = 0 To $numtest - 1
        __GetKeyByHex_ArrayBased_Samoth2($random[$i])
    Next
    $testCFinish = StringLeft(TimerDiff($testCStart) * 0.001, 7)

    ConsoleWrite("Done ! " & "Result : " & $testCFinish & " sec(s)" & @CRLF)
    #EndRegion Test C ------------------------------
    
    If $numtest = 300000 Then
        Exit
    Else
        _longtest()
    EndIf
EndFunc   ;==>_Test


; #FUNCTION# ===================================================================
; Name :               __GetKeyType
; Description:      Returns Hexadecimal or Aplha key for specified key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns -1
; Author(s):        Valuater, FireFox
; Note(s):          Thanks Valuater... 8)
;===============================================================================
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_SwitchNumber

; #FUNCTION# ===================================================================
; Name :               __GetKeyType
; Description:      Returns Hexadecimal or Aplha key for specified key
; Parameter(s):     HexKey
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns -1
; Author(s):        Samoth, Valuater, FireFox
; Note(s):          Thanks Valuater... 8)
;===============================================================================
Func _GetKeyByHex_SwitchNumber_Samoth($sHexKey)
    $sHexKey = Dec($sHexKey)
    Switch $sHexKey
        Case 1 To 37
            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"
            EndSwitch
        Case 38 To 68
            Switch $sHexKey
                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"
            EndSwitch
        Case 96 To 91
            Switch $sHexKey
                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"
            EndSwitch
        Case 92 To 115
            Switch $sHexKey
                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"
            EndSwitch
        Case 116 To 165
            Switch $sHexKey
                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
    EndSwitch
    Return -1
EndFunc   ;==>_GetKeyByHex_SwitchNumber_Samoth

; #FUNCTION# ===================================================================
; Name :               __GetKeyByHex_ArrayBased_Samoth2
; Description:      Returns Hexadecimal or Aplha key for specified key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns -1
; Author(s):        Samoth
; Note(s):          Thanks Valuater... 8)
;===============================================================================
Func __GetKeyByHex_ArrayBased_Samoth2($iKeyIn = 3)
    $iKeyIn = Dec($iKeyIn) - 1
    If $iKeyIn >= 165 Then Return -1
    If $a_Keys[$iKeyIn] <> "" Then Return $a_Keys[$iKeyIn]
    Return -1
EndFunc   ;==>__GetKeyByHex_ArrayBased_Samoth2
Link to comment
Share on other sites

I don't know why I can't edit posts after I reloggedin.

I had another little idea optimizing the last tiny bit of speed...

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\user\BWI\AutoIt\numbers.au3"    

----------SHORT TEST----------
Generating random numbers...Done !
Doing test A...Done ! Result : 0.24618 sec(s)
Doing test B...Done ! Result : 0.12587 sec(s)
Doing test C...Done ! Result : 0.06766 sec(s)


----------LONG TEST----------
Generating random numbers...Done !
Doing test A...Done ! Result : 7.46660 sec(s)
Doing test B...Done ! Result : 3.72427 sec(s)
Doing test C...Done ! Result : 2.36960 sec(s)
>Exit code: 0    Time: 15.797

Only posting my optimizations... For full code snip it from my previous post.

I added the default value at index 0. This saves a subtraction by 1 every time. Then I just changed the global Array to have mixed content (strings and integers) which will save another comparison everytime and allows to return the result immediately. I know one shouldn't do this, but for the result is static it doesn't mess anything. There are 59 spaces in my array by the way. This optimization saves a peek over a third (36,3%) instead of a fourth compared to my nested switch-blocks before and a peek over two thirds (68,2%) compared to the linear switch-block of Valuater and FireFox.

Global $a_Keys[166] = [-1, "LeftMouse", "RightMouse", -1, "MiddleMouse", "X1Mouse", "X2Mouse", -1, _
    "BACKSPACE", "TAB", -1, -1, "CLEAR", "ENTER", -1, -1, "SHIFT", "CTRL", "ALT", "PAUSE", _
    "CAPSLOCK", -1, -1, -1, -1, -1, -1, "ESC", -1, -1, -1, -1, "SPACEBAR", "PAGE UP", "PAGE DOWN", _
    "END", "HOME", "LEFT", "UP", "RIGHT", "DOWN", "SELECT", "PRINT", "EXECUTE", "PRINT SCREEN", _
    "INS", "DEL", -1, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", -1, -1, -1, -1, -1, -1, _
    -1, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", _
    "S", "T", "U", "V", "W", "X", "Y", "Z", "LWin", "RWin", -1, -1, -1, "0'", "1'", "2'", "3'", _
    "4'", "5'", "6'", "7'", "8'", "9'", "Multiply", "Add", "Separator", "Subtract", "Decimal", _
    "Divide", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", _
    -1, -1, "F16", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "NUM LOCK", _
    "SCROLL LOCK", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "LSHIFT", "RSHIFT", _
    "LCTRL", "RCTRL", "LMENU", "RMENU"]

; #FUNCTION# ===================================================================
; Name :               __GetKeyByHex_ArrayBased_Samoth2
; Description:      Returns Aplha key for specified key
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns Key
;                   On Failure - Returns -1
; Author(s):        Samoth
; Note(s):          Thanks Valuater... 8)
;===============================================================================
Func __GetKeyByHex_ArrayBased_Samoth2($iKeyIn = 0)
    $iKeyIn = Dec($iKeyIn)
    If $iKeyIn > 165 Then Return -1
    Return $a_Keys[$iKeyIn]
EndFunc   ;==>__GetKeyByHex_ArrayBased_Samoth2
Link to comment
Share on other sites

  • 9 months later...
Link to comment
Share on other sites

  • 5 months later...

Hi FireFox

I´m a constant user of your functions, and would like to thanks you for all your support during all these years.

Now is time to suggest you, in Is_PressedUDF (that´s correct place?), to think in win8. It is comming,and lots of gestures with it.

I can list some I consider more important. Some already work on my win7 notebook with mouse pad.

- zoom

- rotate

What do you think?

Jose

Edited by joseLB
Link to comment
Share on other sites

I´m a constant user of your functions, and would like to thanks you for all your support during all these years.

You're welcome :)

Now is time to suggest you, in Is_PressedUDF (that´s correct place?), to think in win8. It is comming,and lots of gestures with it.

I can list some I consider more important. Some already work on my win7 notebook with mouse pad.

- zoom

- rotate

What do you think?

Jose

I'm not going to install Windows 8, it's for touchscreens and I don't want to own one.

The problem is that I don't know how the gestures are handled in Win8, has it some dll events like the keyboad keys here, or it's simply advanced cursor moving analyzer ?

I have two projects in my mind for the moment; I don't think that It's hard to do, you can do it by searching on the msdn if there is some infos for this.

Of course, I will help you if needed.

Br, FireFox.

Edited by FireFox
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...