Jump to content
Sign in to follow this  
johnmcloud

_IsPressed + WinGetTitle, some problem

Recommended Posts

johnmcloud

Hi guys, i have this script:

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

Opt("GUICloseOnESC", 1)

Global $GUI_1

$GUIHeight = 25
$GUIWidth = 50

$GUI_1 = GUICreate("A", $GUIWidth, $GUIHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW)
$Focus_GUI_1 = GUICtrlCreateLabel("", 0, 0, $GUIWidth, $GUIHeight)
GUISetState()

Global_Func()

Func Global_Func()
While 1
  If _IsPressed(01) Then
  If WinGetTitle("A") = True Then
    $GUI_Pos_1 = GUIGetCursorInfo($GUI_1)
    If IsArray($GUI_Pos_1) Then
     If $GUI_Pos_1[4] = $Focus_GUI_1 Then
      MsgBox(0, 0, "click")
     EndIf
    EndIf
   EndIf
  EndIf
WEnd
EndFunc   ;==>Global_Func

Work, but work everytime, also if a window/software/whatever is on it, so it's a problem for me. How to make _IsPressed work only if the GUI is Active or Focus?

Thanks for help

Edited by johnmcloud

Share this post


Link to post
Share on other sites
martin

If you omit the parameter from GuiGetCursorInfo then @error is 1if your gui is not active, so you don't need _IsPressed or "If WInGetTitle.."


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
somdcomputerguy

Or the WinGetState() function could be used somehow..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
johnmcloud

Thanks for answer.

I need _IsPressed, i want to check with a click if the GUI is active or not.

For the @error and WinGetState, can you guys post an example? Thanks

Share this post


Link to post
Share on other sites
somdcomputerguy

If IsVisible("A") Then MsgBox(0, '', 'Yay!')

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 15) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>IsVisible

See WinGetState to learn how I came up with 15. You might need another combination there.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
johnmcloud

I have tested the WinGetState, but...

Like this work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
Opt("GUICloseOnESC", 1)

Global $GUI_1

$GUIHeight = 250
$GUIWidth = 500

$GUI_1 = GUICreate("A", $GUIWidth, $GUIHeight, 0, 0)
$Focus_GUI_1 = GUICtrlCreateLabel("", 0, 0, $GUIWidth, $GUIHeight)
GUISetState()

Global_Func()

Func Global_Func()
While 1
  If IsVisible("A") Then
   If _IsPressed(01) Then
    $GUI_Pos_1 = GUIGetCursorInfo($GUI_1)
    If IsArray($GUI_Pos_1) Then
     If $GUI_Pos_1[4] = $Focus_GUI_1 Then
      MsgBox(0, 0, "click")
     EndIf
    EndIf
   EndIf
  EndIf
WEnd
EndFunc   ;==>Global_Func

Func IsVisible($handle)
If BitAND(WinGetState($handle), 8) Then
  Return 1
Else
  Return 0
EndIf
EndFunc   ;==>IsVisible

But if i make the GUI with $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW not:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
Opt("GUICloseOnESC", 1)

Global $GUI_1

$GUIHeight = 250
$GUIWidth = 500

$GUI_1 = GUICreate("A", $GUIWidth, $GUIHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW)
$Focus_GUI_1 = GUICtrlCreateLabel("", 0, 0, $GUIWidth, $GUIHeight)
GUISetState()

Global_Func()

Func Global_Func()
While 1
  If IsVisible("A") Then
   If _IsPressed(01) Then
    $GUI_Pos_1 = GUIGetCursorInfo($GUI_1)
    If IsArray($GUI_Pos_1) Then
     If $GUI_Pos_1[4] = $Focus_GUI_1 Then
      MsgBox(0, 0, "click")
     EndIf
    EndIf
   EndIf
  EndIf
WEnd
EndFunc   ;==>Global_Func

Func IsVisible($handle)
If BitAND(WinGetState($handle), 8) Then
  Return 1
Else
  Return 0
EndIf
EndFunc   ;==>IsVisible

What is wrong? Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites
johnmcloud

I have removed _IsPressed, but work everytime :oops:

$GUI_Pos = GUIGetCursorInfo($GUI_1)
   If IsArray($GUI_Pos) Then
    If $GUI_Pos[2] = 1 And $GUI_Pos[4] = $Focus_GUI_1 Then
     MsgBox(0, 0, "click")
    EndIf
   EndIf

Please a little help

Share this post


Link to post
Share on other sites
johnmcloud

Seem nothing work with combination of $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_LAYERED...

I have try to change approach with:

1) Label like a button --> fail if GUI has $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_LAYERED

2) $GUI_EVENT_PRIMARYUP --> fail if GUI has $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_LAYERED

3) GUIGetCursorInfo --> Work everytime also if GUI is hide by another window/software

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>

$GUI_1 = GUICreate("Form1", 800, 600, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_LAYERED)
$Test = GUICtrlCreateLabel("",800, 600, 0, 0)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_PRIMARYUP
            MsgBox(0, 'Title', 'Text')
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Test
            MsgBox(0, 'Title', 'Text')
    EndSwitch
WEnd

I really ran out of ideas...

Wait for some volunteers :oops:

Edited by johnmcloud

Share this post


Link to post
Share on other sites
BrewManNH

Your label's parameters are mixed up see the code below for the fix. I also got rid of the msgbox functions and used consolewrite instead because the MsgBox wasn't letting the script see the PrimaryUp.

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>


$GUI_1 = GUICreate("Form1", 800, 600, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED));<<<<<<< BTW, this will create an invisible GUI/Label
$Test = GUICtrlCreateLabel("THIS IS A TEST LABEL", 0, 0, 800, 600) ; <<<<<<<<<<<<< You had the size set to 0,0 and the location set to 800,600
GUISetState()

While 1
    Switch GUIGetMsg()
    Case $Test
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Test = ' & $Test & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
        Case $GUI_EVENT_PRIMARYUP
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_PRIMARYUP = ' & $GUI_EVENT_PRIMARYUP & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
johnmcloud

BrewManNH work only if i remove the $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED)

I know the GUI is invisible :oops: , the object is have an invisible GUI + invisible Label like button with two method ( on click and on mouse hover )

No response by Console, i have try to click everyware but nothing

Edited by johnmcloud

Share this post


Link to post
Share on other sites
BrewManNH

Are you running this from SciTE? Because when I do, it works everytime I click the window where the GUI should be, I get a consolewrite for $Test and then another for $GUI_EVENT_PRIMARYUP right after it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
johnmcloud

Sure, from Scite, click on F5 and click everywere ( on VM the resolution is 800x600, so whatever i click i need to see some response from console ) but nothing. My version is 3.3.8.0

Share this post


Link to post
Share on other sites
BrewManNH

Are you running the script on the VM?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
johnmcloud

Yeah, it's a problem? From here i can do only on a VM, but every script tested working fine. I have change ConsoleWrite with MsgBox, nothing change, no messages. Work only if i remove the exStyle

Edited by johnmcloud

Share this post


Link to post
Share on other sites
BrewManNH

Try running it without the extended style parameters so that you can see if the label is there and you can then click on it to see if it's working. I haven't done any scripting on a VM but I don't see why it wouldn't work.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
johnmcloud

Without the extended style work, also my script posted before work, but i need with extended style :oops:

P.S I'm on XP SP3

@@ Debug(14) : $Test = 3
>Error code: 0
@@ Debug(16) : $GUI_EVENT_PRIMARYUP = -8
>Error code: 0

EDIT: Take a look to post #6, same problem. Maybe a bug? Or this combination of extended style not work on XP? I really don't know...However, my first script post on #1 work, but work also if another window is on it like TOPMOST attribute.

Edited by johnmcloud

Share this post


Link to post
Share on other sites
johnmcloud

No idea? It's so impossible to click on a label of a invisible GUI?

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • danusko
      By danusko
      Hi, 
      I have autoit program on my computer only portable version. I use Autoit vs 3.1.1.68
      I want to use WinGetTitle but it always return 0. 
      I want to use it for retriev windows title and then i want to switch between windows. 
      E.g. - On start is msgbox where is info - "now choose yourt first window", i click first win - e.g. Excel, then 2. msgbox "now choose your 2. window" and i choose e.g. window folder. Then i want, that my script will switch between this windws and make my routine. 
      But my test code for retrieve win title still return 0. I try this on comp in work. I dont have admin rights but i belive, that this is not a reason, bacause Au3.SPY, show me win title correctly. 
      This is my sample code. 
      Pls. any suggestions?
      thx a lot
      Sleep( 2000 ) ; Allows switching to some other window to see if can get its title. $title = WinGetTitle("[active]") If $title Then MsgBox(0, "", $title) Else MsgBox(0, "", "nothing") EndIf  
    • Miliardsto
      By Miliardsto
      Hello I want to know which one from arrow key was pressed the last.
      <^V> - need only which arrow
      However I want to call function some seconds after pressed to it must be stored somewhere, not simply if ispressed.
      How to achieve that?
    • TheOnlyOne
      By TheOnlyOne
      Hi,
      I am trying to make some stuff easier for me so when i click on the buttons on the side of my mouse it does some function. I have 4 extra buttons on my mouse and would like to utilize all of them. I have looked at _ispressed but that only seems to have two:
          05 X1 mouse button
          06 X2 mouse button
       
      Those two works fine, I just want to know if there is a way to check if the other two buttons on my mouse is clicked ?
    • TheFixer
      By TheFixer
      Basically i am trying to make a script that detects if the currently active window is 1920 x 1080 or bigger. If it detects a window that is active, that is indeed that size. It will do some stuff. 
      The problem i am having is that it is detecting my desktop whenever i click on my desktop, so it's doing stuff when i don't want it to.

      So all i need to know, is how can i do a simple check to see if a window = a title.

      Here is what i have so far
      $wintitledesktop = WinGetTitle("[ACTIVE]") If not $wintitledesktop = "Program Manager" Then ;does stuff endif Program Manager is what my desktop is called btw. 

      The problem with that code is that the script is still detecting the desktop and doing the code.
       
      In case you need the whole section of the code, here it is.

       
      $winsizecheck1 = WinGetClientSize("[ACTIVE]") $wintitledesktop = WinGetTitle("[ACTIVE]") If WinActive("[ACTIVE]") Then sleep(100) If $winsizecheck1[0] >= 1920 Then If $winsizecheck1[1] >= 1080 Then If not $wintitledesktop = "Program Manager" Then $gamesfolderstate = WinGetState($gamesfolder) If WinExists($gamesfolder) Then If Not BitAND($gamesfolderstate, 16) Then WinSetState($gamesfolder,"",@SW_MINIMIZE) EndIf EndIf EndIf EndIf EndIf EndIf  
    • rm65453
      By rm65453
      Hi Everyone,
       
      I have been using a script at work for the last 6 months or so. It gets some information from the window title and keeps it in its memory for retrieval. 
       
      currently I am running an infinite loop to look for the window title, the information in the memory is only updated if a few window title is detected.
       
      The trouble with this approach as you can see, is the cpu usage. I was wondering if somehow I can only run this script when a windows change event occurs, otherwise the script stays dormant.
       
      I have no idea how to do that, searched on forum and found some solutions that were years old and did not work for me.
       
      Thanks
×