Jump to content

_isPressed Key ALT is big problem


Recommended Posts

hello guys. im working on best hotkeys system. there is a problem with ALT. CTRL and SHIFT working good but i have same function for ALT and it work like SWITCH (unwanted) any tips how fix problem ?? 

stupid question what sense to add $hDLL = DllOpen("user32.dll") ??

here is my code i started today

#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
HotKeySet("{q}", "_quit")
$GUI = GUICreate("set hotkeys", -1,-1)
GUISetState()
$button_hotkey = (GUICtrlCreateButton("", 80, 30, 150, 25))

$start = False
$CTRL = False
$SHIFT = False
$ALT = False
$FUNC_KEY = False
$key = False
$klawisz_shift = ""
$klawisz_ctrl = ""
$klawisz_alt = ""


While 1
    $Msg = GUIGetMsg()
            Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $button_hotkey
                    $start = True
                    $SHIFT = False
                    $CTRL = False
                    $ALT = False
                    $FUNC_KEY = False
                    $key = False
                    $klawisz_shift = ""
                    $klawisz_ctrl = ""
                    $klawisz_alt = ""
                    GUICtrlSetData($button_hotkey, "?")
    EndSwitch


        If $start = True And _IsPressed('10') and $SHIFT = False Then
            $klawisz_shift = "SHIFT + "
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $SHIFT = True
            $FUNC_KEY = True

        ElseIf $start = True And Not _IsPressed("10") And $SHIFT = True Then
            $klawisz_shift = ""
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $SHIFT = False
            $FUNC_KEY = False
        EndIf

        If $start = True And _IsPressed('11') and $CTRL = False Then
            $klawisz_ctrl = "CTRL + "
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $CTRL = True
            $FUNC_KEY = True

        ElseIf $start = True And Not _IsPressed("11") And $CTRL = True Then
            $klawisz_ctrl = ""
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $CTRL = False
            $FUNC_KEY = False
        EndIf

        If $start = True And _IsPressed('12') and $ALT = False Then
            $klawisz_alt = "ALT + "
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $ALT = True
            $FUNC_KEY = True

        ElseIf $start = True And Not _IsPressed("12") And $ALT = True  Then
            $klawisz_alt = ""
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt)
            $ALT = False
            $FUNC_KEY = False
        EndIf

 ;/////// /////// /////// /////// /////// /////// /////// /////// ///////

        If _IsPressed('31') and $FUNC_KEY = True And $key = False Then
            $klawisz1 = "1"
            GUICtrlSetData($button_hotkey, $klawisz_shift&$klawisz_ctrl&$klawisz_alt&$klawisz1)
            $key = True
            $FUNC_KEY = False
            $start = False
        EndIf
WEnd



Func _quit()
    Exit
EndFunc   ;==>_quit

 

Link to comment
Share on other sites

It's because of GUI...

GUISetState(@SW_DISABLE)

Disabling it makes ALT no more work like a switch, but then you can't use GUI :/
ALT is used on toolbars, for example you press ALT, and you can choose something from toolbar using arrows on your keyboard, some keys, and etc.. So ALT in your GUI goes to your toolbar(which doesn't exist) and pressing it again goes in normal state.

Example:
toolbar6.png

You press ALT button in some GUI with toolbar, and when you press it, there's underlined characters, and pressing it again removes underlines.

So ALT switches control from GUI to toolbar and toolbar to GUI.



You can try this code, and try pressing ALT button:
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 273, 103, 305, 198)
$MenuItem3 = GUICtrlCreateMenu("ABC")
$MenuItem6 = GUICtrlCreateMenuItem("MenuItem6", $MenuItem3)
$MenuItem5 = GUICtrlCreateMenu("MenuItem5", $MenuItem3)
$MenuItem16 = GUICtrlCreateMenu("MenuItem16", $MenuItem5)
$MenuItem18 = GUICtrlCreateMenu("MenuItem18", $MenuItem16)
$MenuItem19 = GUICtrlCreateMenuItem("MenuItem19", $MenuItem18)
$MenuItem17 = GUICtrlCreateMenuItem("MenuItem17", $MenuItem16)
$MenuItem15 = GUICtrlCreateMenuItem("MenuItem15", $MenuItem5)
$MenuItem14 = GUICtrlCreateMenuItem("MenuItem14", $MenuItem5)
$MenuItem4 = GUICtrlCreateMenuItem("MenuItem4", $MenuItem3)
$MenuItem2 = GUICtrlCreateMenu("ABCD")
$MenuItem10 = GUICtrlCreateMenu("MenuItem10", $MenuItem2)
$MenuItem13 = GUICtrlCreateMenuItem("MenuItem13", $MenuItem10)
$MenuItem12 = GUICtrlCreateMenuItem("MenuItem12", $MenuItem10)
$MenuItem11 = GUICtrlCreateMenuItem("MenuItem11", $MenuItem10)
$MenuItem9 = GUICtrlCreateMenuItem("MenuItem9", $MenuItem2)
$MenuItem8 = GUICtrlCreateMenuItem("MenuItem8", $MenuItem2)
$MenuItem7 = GUICtrlCreateMenuItem("MenuItem7", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("EFDGE")
$MenuItem20 = GUICtrlCreateMenu("MenuItem20", $MenuItem1)
$MenuItem21 = GUICtrlCreateMenuItem("MenuItem21", $MenuItem20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


I'm not sure how to bypass this thing... I hope somebody else will help you!
 

Sorry for my bad english.

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

21 hours ago, Verssuss said:

what sense to add $hDLL = DllOpen("user32.dll") ??

It's faster to open dll.
If you don't open it, _IsPressed opens and closes every time this dll.

Try this:

$t=100


#include <Misc.au3>
$ti = TimerInit()
For $a = 1 to $t
For $i = 0x01 to 0xDD
    _IsPressed(Hex($i,2))
Next
Next
$ms1=Round(TimerDiff($ti))
$ti = TimerInit()
$dll = DllOpen("user32.dll")
For $a = 1 to $t
For $i = 0x01 to 0xDD
    _IsPressed(Hex($i,2), $dll)
Next
Next
DllClose($dll)
$ms2=Round(TimerDiff($ti))
ConsoleWrite("Without opening user32.dll: "&$ms1&"ms" & @CRLF)
ConsoleWrite("With opening user32.dll: "&$ms2&"ms" & @CRLF)
ConsoleWrite(@CRLF&"It's faster "&Round(100-$ms2/$ms1*100)&"% than without opening user32.dll." & @CRLF)
Without opening user32.dll: 1646ms
With opening user32.dll: 1303ms

It's faster 21% than without opening user32.dll.

 

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...