maniootek Posted January 21, 2022 Posted January 21, 2022 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?
SOLVE-SMART Posted January 21, 2022 Posted January 21, 2022 (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 January 21, 2022 by SOLVE-SMART ==> AutoIt related: ๐ GitHub, ๐ Discord Server, ๐ Cheat Sheet Reveal hidden contents ๐ 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)
maniootek Posted January 21, 2022 Author Posted January 21, 2022 On 1/21/2022 at 10:57 AM, 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! Expand 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?
SOLVE-SMART Posted January 21, 2022 Posted January 21, 2022 (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 Expand 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 January 21, 2022 by SOLVE-SMART ==> AutoIt related: ๐ GitHub, ๐ Discord Server, ๐ Cheat Sheet Reveal hidden contents ๐ 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)
Nine Posted January 21, 2022 Posted January 21, 2022 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. โThey did not know it was impossible, so they did itโ โ Mark Twain Reveal hidden contents Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
SOLVE-SMART Posted January 21, 2022 Posted January 21, 2022 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. Expand Besides the explanation I am still excited what @maniootek will answer about the post above. Best regards Sven ________________Stay innovative! ==> AutoIt related: ๐ GitHub, ๐ Discord Server, ๐ Cheat Sheet Reveal hidden contents ๐ 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now