Jump to content

Recommended Posts

Posted

I am trying to make function which will check if shift key is pressed. I wrote the script but it does not work properly in some cases.

When I run this script from scite or from run option with SHIFT key pressed down, it suppose to show me gui message "You can now release SHIFT key" but I can't see it on the screen. It is hidden by other window opened before.

#include <Misc.au3>
#include <WindowsConstants.au3>

WaitForShiftKey()

Func WaitForShiftKey()
    If _IsPressed("10") Then
        Beep(500, 500)
        Local $hGUI_ShiftPressed = GUICreate(@ScriptName, 250, 10)
        GUISetStyle($WS_POPUPWINDOW, $WS_EX_TOPMOST, $hGUI_ShiftPressed)
        Local $idLabel = GUICtrlCreateLabel("You can now release SHIFT key...", 5, 5, 240)
        GUICtrlSetFont($idLabel, 9, 600, 0, "Segoe UI")
        GUISetState(@SW_SHOW, $hGUI_ShiftPressed)

        While _IsPressed("10") ;shift = 10, ctrl = 11, alt = 12
            Sleep(10)
        WEnd

        GUIDelete($hGUI_ShiftPressed)
        Return 1
    EndIf
EndFunc

The problem can be fixed when I add "msgbox(0,0,0)" code on the first line of function and start hold shift key when i see msgbox and then click "ok" button.

Maybe there is something wrong with my pc or I miss something?

Posted (edited)

Hi maniootek,

I could reproduce your described behavior. Please try the following version which works for me without an additional messages box.

#include <Misc.au3>
#include <WindowsConstants.au3>

WaitForShiftKey()

Func WaitForShiftKey()
    If _IsPressed("10") Then
        Beep(500, 500)

        Local $hGUI_ShiftPressed = GUICreate(@ScriptName, 250, 20, Default, Default, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
        Local $idLabel = GUICtrlCreateLabel("You can now release SHIFT key...", 5, 5, 240)
        GUICtrlSetFont($idLabel, 9, 600, 0, "Segoe UI")
        GUISetState(@SW_SHOW, $hGUI_ShiftPressed)

        While _IsPressed("10") ;shift = 10, ctrl = 11, alt = 12
            Sleep(10)
        WEnd

        GUIDelete($hGUI_ShiftPressed)
        Return 1
    EndIf
EndFunc

Basically I increased the gui height from 10 to 20 and (that's the important part) create the gui with the styles directly instead of using the GUISetStyle() function.
This was only a tryout, but it seems to be working as expected in my case.

Please let me know if this works for you too, thanks :).

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Posted
44 minutes ago, SOLVE-SMART said:

Hi maniootek,

I could reproduce your described behavior. Please try the following version which works for me without an additional messages box.

#include <Misc.au3>
#include <WindowsConstants.au3>

WaitForShiftKey()

Func WaitForShiftKey()
    If _IsPressed("10") Then
        Beep(500, 500)

        Local $hGUI_ShiftPressed = GUICreate(@ScriptName, 250, 20, Default, Default, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
        Local $idLabel = GUICtrlCreateLabel("You can now release SHIFT key...", 5, 5, 240)
        GUICtrlSetFont($idLabel, 9, 600, 0, "Segoe UI")
        GUISetState(@SW_SHOW, $hGUI_ShiftPressed)

        While _IsPressed("10") ;shift = 10, ctrl = 11, alt = 12
            Sleep(10)
        WEnd

        GUIDelete($hGUI_ShiftPressed)
        Return 1
    EndIf
EndFunc

Basically I increased the gui height from 10 to 20 and (that's the important part) create the gui with the styles directly instead of using the GUISetStyle() function.
This was only a tryout, but it seems to be working as expected in my case.

Please let me know if this works for you too, thanks :).

Best regards
Sven

________________
Stay innovative!

Sven, thank you for taking time to test my script. Your version is working. ย GUI is visible on the screen when shift is pressed. I am surprised that onlyย gui style define was the problem.

Anyway, there is still one problem with the script. When SHIFT key is depressed and gui is deletedย the other explorer window becomes active. Can you try on your side too?

Posted (edited)

Hi again,

yes I was also confused about the gui style behavior. Anyway, I am not sure what do you mean by:

Quote

the other explorer window becomes active

  • I use VSCode to execute all my AutoIt stuff, also your example script.
    • So when I press F5 to run the script and right afterwards the SHIFT key, I get the GUI until the key is released.
    • Then the focus do not return to the last focused window (which were VSCode) => it choose the browser (in my case) as new/or returned focused window.

So if you mean this unexpected behavior - yes it's also the case for me.

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Posted

I was curious to understand why @maniootekย way was not working properly.ย  At first glance, it should, but it's not.

#include <GUIConstants.au3>
#include <WinAPISysWin.au3>

Local $hWnd = GUICreate(@ScriptName, 250, 30)
GUISetStyle($WS_POPUPWINDOW, $WS_EX_TOPMOST, $hWnd)
Local $idLabel = GUICtrlCreateLabel("You can now release SHIFT key...", 5, 5, 240)
GUICtrlSetFont($idLabel, 9, 600, 0, "Segoe UI")

GUISetState(@SW_SHOW, $hWnd)

Sleep(2000)

Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
ConsoleWrite(Hex($Style, 8) & @CRLF)
Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
ConsoleWrite($Style & @CRLF)

GUIDelete()

Local $hWnd = GUICreate(@ScriptName, 250, 30, Default, Default, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
Local $idLabel = GUICtrlCreateLabel("You can now release SHIFT key...", 5, 5, 240)
GUICtrlSetFont($idLabel, 9, 600, 0, "Segoe UI")
GUISetState(@SW_SHOW, $hWnd)

Sleep(2000)

Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
ConsoleWrite(Hex($Style, 8) & @CRLF)
Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
ConsoleWrite($Style & @CRLF)

GUIDelete()

If you run this code, you will see that some styles are not applied correctly and some are not applied at all.ย  My understanding is that when you create a GUI, it will automatically apply some default styles and extended styles.ย  With the GUISetStyle, you are trying to remove all styles to be replaced by others.ย  Windows does not seem to allow some of the changes.ย  I have seen that in the past, not all styles can be applied on the fly.

Posted

Hi Nine,

of course, I guess you are right ๐Ÿ‘ . As I remember correctly, I had a similar outcome in the past regarding such styles.

Quote

My understanding is that when you create a GUI, it will automatically apply some default styles and extended styles. With the GUISetStyle, you are trying to remove all styles to be replaced by others.

Besides the explanation I am still excited what @maniootek will answer about the post above.

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

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
  • Recently Browsing   0 members

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