Jump to content

amin84

Active Members
  • Posts

    156
  • Joined

  • Last visited

Everything posted by amin84

  1. Hello, I'm trying to create a simple application that will detect what modifier keys (ALT, CTRL, SHIFT, WIN) are pressed + one non-modifier key only if the input field is selected (active): I tried a few ways but it either doesn't work properly. Any help is appreciated. Thanks.
  2. I just did a test with Sleep(5000) and it had no lag showing the GUIs or executing the hotkey. The while loop is only here to keep the program running (not exit). OnEvent is listening and it is separate from the while loop. Now if you put something in that while loop, it will affect it. So use OnEvent calls instead. It makes scenes now.
  3. I was wondering if there is another way of doing this without having sleep in there. And if there is no way, what is the best sleep amount that wouldn't slowdown the computer? Thanks for the replies btw.
  4. I managed to make it work using OnEvents for tray and both GUIs. #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #include <Constants.au3> #include <StaticConstants.au3> Opt('TrayMenuMode',3) Opt("TrayOnEventMode",1) Opt('TrayAutoPause',0) Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 0) TraySetClick(8) Dim $mainGui, $showChildBtn, $childGui, $hideChildBtn $showMainGuiTray = TrayCreateItem('Show Main Gui...') TrayItemSetOnEvent(-1, "mainGui") TrayCreateItem('') $exitTray = TrayCreateItem('Exit') TrayItemSetOnEvent(-1, "_exit") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, '_toggle') While 1 Sleep(100) WEnd Exit Func _toggle() ConsoleWrite('DOUBLE'&@LF) EndFunc Func mainGui() $mainGui = GUICreate("Parent", 320, 240, -1, -1, $WS_SYSMENU) $showChildBtn = GUICtrlCreateButton("Show Child", 5, 5) GUICtrlSetOnEvent(-1, "showChild") GUISetOnEvent($GUI_EVENT_CLOSE, "guiDel", $mainGui) GUISetState(@SW_SHOW, $mainGui) EndFunc Func guiDel() GUIDelete($mainGui) EndFunc Func childGui() $childGui = GUICreate("child",200,200,-1,-1,$WS_EX_TOOLWINDOW,$WS_EX_MDICHILD,$mainGui) $hideChildBtn = GUICtrlCreateButton("Hide Child", 5, 5) GUICtrlSetOnEvent(-1, "hideChild") GUISetState(@SW_SHOW, $childGui) EndFunc Func showChild() GUISetState(@SW_DISABLE, $mainGui) childGui() WinActivate($childGui) EndFunc Func hideChild() GUIDelete($childGui) GUISetState(@SW_ENABLE, $mainGui) WinActivate($mainGui) EndFunc Func _exit() Exit EndFunc I just don't like that Sleep(100) thing! Is there a another way to do this?
  5. Perfect. Thank you. That works!
  6. Hello, I'm trying to make a tray menu that will open the mainGui and then mainGui will open a childGui. This is what I've been using when I needed tray menu and one mainGui like settings for example: #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> Opt('TrayMenuMode',3) Opt('TrayAutoPause',0) Opt("GUICloseOnESC", 0) Global $mainGui $showMainGuiTray = TrayCreateItem('Show Main Gui...') TrayCreateItem('') $exitTray = TrayCreateItem('Exit') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($mainGui) EndSwitch $tMsg = TrayGetMsg() Switch $tMsg Case $exitTray Exit Case $showMainGuiTray mainGui() EndSwitch WEnd Func mainGui() $mainGui = GUICreate("Parent", 320, 240, -1, -1, $WS_SYSMENU) GUISetState(@SW_SHOW, $mainGui) EndFunc But I can't make it work when I need additional child GUI that will be opened by the main GUI. I've tried different things but I don't know how to manage clicks from tray and two GUIs. This is what I have so far but doesn't work at all! #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> Opt('TrayMenuMode',3) Opt('TrayAutoPause',0) Opt("GUICloseOnESC", 0) Global $mainGui, $showChildBtn, $childGui, $hideChildBtn $showMainGuiTray = TrayCreateItem('Show Main Gui...') TrayCreateItem('') $exitTray = TrayCreateItem('Exit') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($mainGui) Case $showChildBtn GUISetState(@SW_DISABLE, $mainGui) childGui() WinActivate($childGui) Case $hideChildBtn GUIDelete($childGui) GUISetState(@SW_ENABLE, $mainGui) WinActivate($mainGui) EndSwitch $tMsg = TrayGetMsg() Switch $tMsg Case $exitTray Exit Case $showMainGuiTray mainGui() EndSwitch WEnd Func mainGui() $mainGui = GUICreate("Parent", 320, 240, -1, -1, $WS_SYSMENU) $showChildBtn = GUICtrlCreateButton("Show Child", 5, 5) GUISetState(@SW_SHOW, $mainGui) EndFunc Func childGui() $childGui = GUICreate("child",200,200,-1,-1,$WS_EX_TOOLWINDOW,-1,$mainGui) $hideChildBtn = GUICtrlCreateButton("Hide Child", 5, 5) GUISetState(@SW_SHOW, $childGui) EndFunc Thanks.
  7. It seems that AutoIT does not allow toggle between _WinAPI_ShutdownBlockReasonCreate and _WinAPI_ShutdownBlockReasonDestroy using system tray directly. Something happens to _WinAPI_ShutdownBlockReasonCreate as soon as the system tray is clicked and _WinAPI_ShutdownBlockReasonCreate no longer works! Is there anyway to toggle it indirectly using system tray?
  8. Hello, I'm experiencing strange behavior with _WinAPI_ShutdownBlockReasonCreate(). I have this simple script that you can _WinAPI_ShutdownBlockReasonCreate() and _WinAPI_ShutdownBlockReasonDestroy() using Ctrl + Shift + T. When _WinAPI_ShutdownBlockReasonCreate() is called, it will stop system from restarting. Here is the problem. Run this code and it will be disabled by default (computer will log off or restart). Press Ctrl + Shift + T to enable it which it will do _WinAPI_ShutdownBlockReasonCreate(). Now if you try to log off, it won't be able to and it will show that this program needs to close. Press cancel to go back to desktop. If you try to log off again, _WinAPI_ShutdownBlockReasonCreate() still exists which will stop you as expected. Click on the tray icon to open the menu and click anywhere on the desktop to cancel the menu. Now try to log off and it will log off which it should not! _WinAPI_ShutdownBlockReasonCreate() doesn't exists anymore after opening the tray menu! Anybody knows what happens to _WinAPI_ShutdownBlockReasonCreate() when tray menu opens? Here is the code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <StaticConstants.au3> #include <Misc.au3> #include <WinAPISys.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> Global $enabled = False Opt('TrayMenuMode',3) Opt('TrayAutoPause',0) Opt("GUICloseOnESC", 0) HotKeySet('^+t','_guard') Global $g_hForm = GUICreate('DUMMY GUI', 200, 200) GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION') _WinAPI_SetProcessShutdownParameters(0x03FF) ;menu $aboutTray = TrayCreateItem('DEMO') TrayItemSetState(-1,$TRAY_DISABLE) TrayCreateItem('') $enableTray = TrayCreateItem('Enabled'&@TAB&'Ctrl + Shift + T') TrayCreateItem('') $settingsTray = TrayCreateItem('Settings...') TrayCreateItem('') $exitTray = TrayCreateItem('Exit') TraySetState() ;settings $gui = GUICreate("DEMO Settings", 386+7, 114+93, -1, -1, $WS_SYSMENU) TrayTip("", "DISABLED", 0) Func _guard() If Not $enabled Then ;enable it $enabled = True _WinAPI_ShutdownBlockReasonCreate($g_hForm, 'This application is blocking system shutdown because the saving critical data is in progress.') TrayItemSetState($enableTray,$TRAY_CHECKED) TrayTip("", "ENABLED", 0) Else $enabled = False _WinAPI_ShutdownBlockReasonDestroy($g_hForm) TrayItemSetState($enableTray,$TRAY_UNCHECKED) TrayTip("", "DISABLED", 0) EndIf EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $gui) EndSwitch $tMsg = TrayGetMsg() Switch $tMsg Case $enableTray _guard() Case $exitTray Exit EndSwitch WEnd Exit Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $g_hForm If _WinAPI_ShutdownBlockReasonQuery($g_hForm) Then Return 0 EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc Any help is much appreciated. Thanks.
  9. If you want to see if a handle is a "real window", you can use this: Func _isReal($hWnd) $vWinStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) If BitAND(WinGetState($hWnd), 4) = 4 _ And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _ And BitAND($vWinStyle, $WS_MINIMIZE) <> $WS_MINIMIZE _ And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _ And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then Return True EndFunc And you can use it like this $hWnd = WinGetHandle("[ACTIVE]") If _isReal($hWnd) Then ;do something... EndIf Solved.
  10. Hello, I'm trying to detect if no window is active, when a hotkey is pressed. I tried to see if I can use the ClassName: #include <WinAPISysWin.au3> While 1 ConsoleWrite(_WinAPI_GetClassName(WinGetHandle("[ACTIVE]"))&@LF) Sleep(500) WEnd But desktop, Taskbar, SystemTray and Start has their own ClassNames and this way I have to have a black/white list and these ClassNames are probably different in Windows 10 and 7. Is there a better way to detect if no window is active? Thanks.
  11. Oo damn didn't see that! Here is a working script if you want to use system tray menu and GUI at the same time. #include <GUIConstants.au3> Opt('TrayMenuMode',3) Opt('TrayAutoPause',0) $gui = GUICreate("My GUI") $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $showgui = TrayCreateItem("Show") $hidegui = TrayCreateItem("Hide") $exitItem = TrayCreateItem("Exit") TraySetState() GUISetState (@SW_HIDE, $gui) While 1 $tMsg = TrayGetMsg() Switch $tMsg Case $showgui GUISetState(@SW_SHOW, $gui) Case $hidegui GUISetState(@SW_HIDE, $gui) Case $exitItem Exit EndSwitch $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 ConsoleWrite('ok pressed'&@LF) Case $GUI_EVENT_CLOSE Exitloop EndSwitch Wend Thanks.
  12. Hello, How can I use TrayGetMsg with GUIGetMsg? Does anybody know what I'm doing wrong here? #include <GUIConstants.au3> Opt('TrayMenuMode',3) Opt("TrayOnEventMode",1) Opt('TrayAutoPause',0) $gui = GUICreate("My GUI") $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $showgui = TrayCreateItem("Show") $hidegui = TrayCreateItem("Hide") $exitItem = TrayCreateItem("Exit") TraySetState() GUISetState (@SW_HIDE, $gui) While 1 $tMsg = TrayGetMsg() Switch $tMsg Case $showgui GUISetState(@SW_SHOW, $gui) Case $hidegui GUISetState(@SW_HIDE, $gui) Case $exitItem Exit EndSwitch $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 ConsoleWrite('ok pressed'&@LF) Case $GUI_EVENT_CLOSE Exitloop EndSwitch Wend Thanks.
  13. I wrote this using Python 3 and the results were the same in Windows 10. import win32gui hwnd = win32gui.FindWindow(None, 'Untitled - Notepad') x0, y0, x1, y1 = win32gui.GetWindowRect(hwnd) win32gui.MoveWindow(hwnd, x0, y0, 800, 600, True) In Windows 7, WinGetPos and WinGetClientSize return same height and width and this problem doesn't exist in Windows 7. But in Windows 10, WinGetClientSize height is 14 pixels shorter than WinGetPos height and WinGetClinetSize width is 7 pixels shorter than WinGetPos width. This script below will fix this problem in Windows 10 while still working fine in Windows 7 and 8. Func _resize($x, $y) $hWnd = WinGetHandle("[ACTIVE]") ;get handle of active window WinSetState($hWnd, '', @SW_RESTORE) ;some windows will retrun wrong width and height if maximized $wpos = WinGetPos($hWnd) $csiz = WinGetClientSize($hWnd) If @OSVersion == 'WIN_10' Then If $csiz[0] <> $wpos[2] And @OSVersion == 'WIN_10' Then $xf = 14 $yf = 7 Else $xf = 0 $yf = 0 EndIf Else $xf = 0 $yf = 0 EndIf WinMove($hWnd, '', Default, Default, $w+$xf, $h+$yf) EndFunc And this is how to use it. _resize(800,600) I also tested this in Windows 10 with different DPI and it works. @Bilgus, thanks for helping me with this.
  14. I don't know what to do anymore! It resizes properly on only a few applications. The rest are 14 pixels short on x and 7 pixels short on y. Applications that resize properly are: VSCode, Telegram, Photoshop, Applications that do not resize properly are: Windows Explorer, AutoIt SciTE, FileZilla, Audacity, QT Designer, Notepad++, Chrome, Blender, Python IDLE Here is a video demo: https://www.youtube.com/watch?v=0p2qcD_RlrQ And here is the script: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ #NoTrayIcon #RequireAdmin #pragma compile(Icon, resources\main.ico) #pragma compile(UPX, False) #pragma compile(x64, False) #pragma compile(Compression, 9) #pragma compile(FileVersion, 1.0.0.0) #pragma compile(ProductVersion, 1.0.0.0) #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <Misc.au3> #include <resources\ExtMsgBox.au3> #include <ScreenCapture.au3> $title = 'Demo App' $ver = '1.0' AutoItWinSetTitle($title) Opt('TrayMenuMode',3) Opt('TrayAutoPause',0) Opt("GUICloseOnESC", 0) Global Const $WM_USER = 0x0400 Global Const $MY_WM_NOTIFYICON = $WM_USER + 1 Global Const $WM_LBUTTONDOWN = 0x0201 Global $hWnd $resizeTray = TrayCreateItem("Active window: Resize to 800x600") TrayCreateItem("") $exitTray = TrayCreateItem('Exit') TraySetState() HotKeySet("^!t", "ShowTrayMenu") While 1 $Msg = TrayGetMsg() Switch $Msg Case $exitTray Exit Case $TRAY_EVENT_PRIMARYDOWN, $TRAY_EVENT_PRIMARYUP, $TRAY_EVENT_SECONDARYDOWN, $TRAY_EVENT_SECONDARYUP _dMenu() Case $resizeTray _resize($hWnd, 800, 600) EndSwitch WEnd Exit Func _dMenu() TrayItemSetState($resizeTray,$TRAY_DISABLE) EndFunc Func _eMenu() TrayItemSetState($resizeTray,$TRAY_ENABLE) EndFunc Func ShowTrayMenu() $hWnd = WinGetHandle("") ;get handle for active window _eMenu() DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($title), "int", $MY_WM_NOTIFYICON, "int", 0, "int", $WM_LBUTTONDOWN) ;show menu with hotkey EndFunc Func _resize($hWnd, $w, $h) WinMove($hWnd, '', Default, Default, $w, $h) $pos = WinGetPos($hWnd) ConsoleWrite('resized '&$hWnd&', x='&$pos[0]&', y='&$pos[1]&', width='&$pos[2]&', height='&$pos[3]&@LF) WinActivate($hWnd) EndFunc I have also tested this in a Windows 10 VM and the results are the same! UPDATE: This works properly on all applications in Windows 7! Anybody knows how we can fix this in Windows 10?
  15. Here is a very simple test app. Run this, then open an Explorer window and press Ctrl + Alt + T. This will resize the window to 800x600 and take a screen shot of that window and save it on your desktop as "resize.jpg". The dimensions of that JPG should be 800x600 but it is 786x593 for some reason (ESC will exit the script)! I tried so many things but nothing worked! #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> HotKeySet("{ESC}", "_exit") HotKeySet("^!t", "_resize") Global $hWnd While 1 Sleep(100) WEnd Func _resize() $hWnd = WinGetHandle("[active]") $pos = WinGetPos($hWnd) WinMove($hWnd, '', $pos[0], $pos[1], 800, 600) ;~ _WinSetClientPos($hWnd, "", 800, 600, $pos[0], $pos[1]) ;~ _WinAPI_MoveWindow($hWnd, $pos[0], $pos[1], 800, 600) ;~ _WinAPI_SetWindowPos($hWnd, $HWND_NOTOPMOST, $pos[0], $pos[1], 800, 600, $SWP_NOMOVE) Sleep(500) _ScreenCapture_CaptureWnd(@DesktopDir&'\resize.jpg', $hWnd) EndFunc Func _exit() Exit EndFunc Even DllCall does not resize it properly!!! DllCall("User32.dll", "int", "MoveWindow", "hwnd", $hWnd, "int", $pos[0], "int", $pos[1], "int", 800, "int", 600, "bool", False)
  16. I didn't know about _SendMessage. Very useful. Perfect. Thank you.
  17. Wow that was very hard to detect! Thanks for the fix. So I stumbled upon this script to see if I can get the handle of active window then show a menu (to change size and other properties of that active window). I tried adding WinGetHandle just before the DllCall in the ShowTrayMenu() but I only get 0x0000000000000000: Func ShowTrayMenu() ConsoleWrite(WinGetHandle('')&@LF) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle("demotraymenu"), _ "int", $MY_WM_NOTIFYICON, _ "int", 0, _ "int", $WM_LBUTTONDOWN) EndFunc This script is kinda hard to understand!
  18. When I run this, and use the hotkey, it first shows Script Paused and Exit menu then when I click Exit, then the next time, it shows About and Exit menu. Shouldn't it just show the About and Exit from the beginning?
  19. Thanks for the replies. None of them worked properly. The first one shows 16 for X and 59 for Y. The second is way off. Just to be clear, what I mean by resizing is to set the whole window to what ever dimension. This includes the title bar thickness (which can change with themes or DPI) and the small thickness around the windows. So far I haven't been able to find a good solution.
  20. Hello, I'm trying to write a simple program that will resize the active window to 800x600 for example but when I measure the dimensions of the resized window, it's slightly off (14px on X and 7px on Y in Windows 10). Also position of 0 on X is 7 pixels off. So to move a window to top left and resize it to 800x600 in Windows 10, I have to do this instead: $hWnd = WinGetTitle ('') WinMove($hWnd, '', -7, 0, 800+14, 600+7) Is there any way to set window size to exactly 800x600 dimensions? Thanks.
  21. Hello, Is there anyway to get .otf font name with AutoIT? I already tried _WinAPI_GetFontName and _WinAPI_GetFontResourceInfo and they return empty. They seems to only work with ttf fonts. Thanks.
  22. Thank you both.
  23. Hello, I'm having trouble getting information from Win32_Processor: https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-processor How does this WMI Query work? Let's say I need to query VMMonitorModeExtensions, Level, ProcessorId, and ProcessorType. How would this work? Thanks.
  24. O wow. That's exactly what I was looking for. I didn't know about @HotKeyPressed. Thanks!
  25. The first way is to loop and create functions but hotkeyset needs the function created already: $ini = @ScriptDir&"\hotkeys.ini" Global $aHotkeys = IniReadSection($ini, "Hotkeys") Global $i For $i = 1 To $aHotkeys[0][0] HotKeySet($aHotkeys[$i][0], $i) Next While 1 Sleep(500) WEnd For $i = 1 To $aHotkeys[0][0] Func Eval($i)&"()" ShellExecute($aHotkeys[$i][1]) EndFunc Next The second way is to make one function with cases which is better cuz the hotkeyset already has the function ready. I just don't know how to create the cases with the array: $ini = @ScriptDir&"\hotkeys.ini" Global $aHotkeys = IniReadSection($ini, "Hotkeys") Global $i For $i = 1 To $aHotkeys[0][0] HotKeySet($aHotkeys[$i][0], "HotKeyPressed") Next While 1 Sleep(500) WEnd Func HotKeyPressed() Switch @HotKeyPressed ;Loop through array and create cases Case Else ;do nothing EndSwitch EndFunc
×
×
  • Create New...