Add keywait to "if" of else script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Add keywait to "if" of else script

Post by Evil-e » 29 May 2023, 13:03

Possible and relevant issues:
v1.1.30.3
Win XP SP3 32b
Firefox browser is v52.9.0 and cannot be updated on my PC
Goal: Enable Keywait for "if" statement


I have the following script to enable MButton to do 2 functions:
1. Cycle "Dark Mode" on / off via "Tap"
2. Bookmark current page via "Hold" T .2
-------------------------------------------------------------------------------------------------------------

Code: Select all

MButton::                                 ;"Tap" cycles Dark Mode
keywait,MButton,t.2                       ;"Hold" 200ms saves bookmark to toolbar
if (errorlevel) {
        BlockInput, On                    ;create Toolbar bookmark of current webpage
        CoordMode, Mouse, Screen
        MouseMove, 1788,48,2              ;add Bookmark
        sleep, 500
        send {LButton down}   ;<------------ window opens slow or fast
        sleep, 50
        send {LButton up}
        sleep, 750                        ;extended delay to be consistent
        CoordMode, Mouse, Screen
        MouseMove, 1824,80,2              ;save Bookmark
        send {LButton down}
        sleep, 5
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove, 1824,354,0             ;cursor upper RH side of webpage
        BlockInput, Off
   }
} else {
        CoordMode, Mouse, Screen          ;moves cursor over "Dark Mode" on / off switch
        MouseMove,1857,51,0
        send {LButton down}               ;cycles "Dark Mode" on / off
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen          ;moves cursor 1"x 6" down RH top of screen
        MouseMove,1860,350,0
}
return
This script is ONLY necessary, because my browser is so out-of-date and have to get very creative with both Chrome and Firefox browsers.

The problem.... the little dialog is not unique via Window Spy and my attempts to get ID for WinWait / WinWaitActive have been futile. Sometimes this "Page Bookmarked" dialog pops right up...... other times it is slow as molasses so my 750ms delay works about 50%+ of the time. If I were to "hold" the MButton until the window fully opened (becomes functional), I would do so and my bookmark save would be successful 100% of the time.

I have tried the following and failed:

Code: Select all

MButton::                                 ;"Tap" cycles Dark Mode
keywait,MButton,t.2                       ;"Hold" 200ms saves bookmark to toolbar
if (errorlevel) {
{
        keywait, MButton
        {
        BlockInput, On                    ;create Toolbar bookmark of current webpage
        CoordMode, Mouse, Screen
        MouseMove, 1788,48,2              ;add Bookmark
        sleep, 500
        send {LButton down}   ;<------------ window opens slow or fast
        sleep, 50
        send {LButton up}
        sleep, 750                        ;extended delay to be consistent
        CoordMode, Mouse, Screen
        MouseMove, 1824,80,2              ;save Bookmark
        send {LButton down}
        sleep, 5
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove, 1824,354,0             ;cursor upper RH side of webpage
        BlockInput, Off
        }
   }
} else {
        [removed so as not to duplicate information]
... and I tried this and failed:

Code: Select all

MButton::                                 ;"Tap" cycles Dark Mode
keywait,MButton,t.2                       ;"Hold" 200ms saves bookmark to toolbar
if (errorlevel) {
        BlockInput, On                    ;create Toolbar bookmark of current webpage
        keywait, MButton
        CoordMode, Mouse, Screen
        MouseMove, 1788,48,2              ;add Bookmark
        sleep, 500
        send {LButton down}   ;<------------ window opens slow or fast
        sleep, 50
        send {LButton up}
        sleep, 750                        ;extended delay to be consistent
        CoordMode, Mouse, Screen
        MouseMove, 1824,80,2              ;save Bookmark
        send {LButton down}
        sleep, 5
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove, 1824,354,0             ;cursor upper RH side of webpage
        BlockInput, Off
        }
   }
} else {
        [removed so as not to duplicate information]
Would like to just "Hold" the MButton for the several seconds it may take for bookmark to save :morebeard:
Screenshot:
LINK: https://photos.app.goo.gl/GyuUVbiEZSajxUJe6
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

BigBrainAFK
Posts: 6
Joined: 20 May 2023, 15:29
Contact:

Re: Add keywait to "if" of else script

Post by BigBrainAFK » 29 May 2023, 13:28

Just a really dumb question but have you tried using Ctrl+D to not need to do the weird mouse movement? I am unsure if that opens the small windows for bookmark editing or not

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Add keywait to "if" of else script

Post by Evil-e » 29 May 2023, 14:04

No such thing as dumb questions, I have always heard. You are correct, but is only on the later versions of Firefox. The problem with my earlier release, is that "Other Bookmarks" is highlighted by default (not even sure where that bookmark ends up, cuz can never find it... lol). I was able to find an archived add-on that makes "Bookmark Toolbar" by default, but MUST manually use the "star" button. When I use "Ctrl-D", my add-on is bypassed and back to "Other Bookmarks" again :(

I am pretty sure that settings to select "default bookmarks location" was introduced shortly after my OS was abandoned by Mozilla :evil: Most of times I come here, are due to issues created by my Win XP. However, I would not exchange it for ANY OS since.

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

BigBrainAFK
Posts: 6
Joined: 20 May 2023, 15:29
Contact:

Re: Add keywait to "if" of else script

Post by BigBrainAFK » 29 May 2023, 14:09

IO just asked because the 59-esr for macos has CMD+D like the new versions.

Anyway the smartest way I can thing of is picking a pixel in the toolbar that goes from normal to the white of the bookmark window.
Get the pixel in the beginning of the macro, click the star and then continuously loop getting the same pixel as before and check if the color changed. if it changes you know the window popped up and you can click the done button/press enter whatever works for you.

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Add keywait to "if" of else script

Post by Evil-e » 29 May 2023, 15:00

@BigBrainAFK ... Thanks! :thumbsup: You are actually the second person now, one last week on a previous unsolved question, that mentioned reading "pixels". Most of AHK code is well over my head and I am about as far from a code junky as anyone can ever meet. My brain sees "mechanical" things, with insane ease. Take anything apart and I can figure out how to put back together or make a part to replace a broken one.

When it comes to AHK scripts, my increase of knowledge is very incremental and my steps must be really small :D I have no doubt that there is a way to determine the ID of this little "Bookmarks" window, but really looked into it last week and simply could not get my head around why I kept getting different ID's :oops:

However, I will look into "pixels" and ID's again and maybe will gain some ground :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

BigBrainAFK
Posts: 6
Joined: 20 May 2023, 15:29
Contact:

Re: Add keywait to "if" of else script

Post by BigBrainAFK » 29 May 2023, 15:11

Im not even sure if that small window will have an easily found ID cause I think its not a window but just a GUI component they draw into the window at the right spot.

For the pixel color just refer to https://www.autohotkey.com/docs/v1/lib/PixelGetColor.htm

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Add keywait to "if" of else script

Post by Evil-e » 29 May 2023, 15:56

@BigBrainAFK ... Thanks for LINK to docs. I am taking a little break from this, as I was working out a number of different scripts that interact and needed to work out the bugs. Yes. a GUI window seems a good call, so will have me some lunch and look into the pixles thing. If I can make sense of it, it my just help me to resolve my issue from last week as well... thanks!

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Add keywait to "if" of else script  Topic is solved

Post by Evil-e » 30 May 2023, 03:52

@BigBrainAFK .... I came up with 2 solutions that each work wonderfully. BlockInput gave me a small issue, but the lack of $ (forget syntax, ATM) was my nemesis on this one :thumbdown:

MButton for Dark Mode cycle (Tap) and bookmark saving (hold):

Code: Select all

$MButton::            ;"Tap" cycles Dark Mode
keywait,MButton,t.2      ;"Hold" 200ms saves bookmark to toolbar
if (errorlevel) {
        BlockInput, On
        CoordMode, Mouse, Screen           ;create Toolbar bookmark of current webpage
        MouseMove, 1788,48,2               ;create Bookmark
        sleep, 500
        send {LButton down}
        sleep, 50
        send {LButton up}
        BlockInput, Off
        {
           keywait, MButton
           {
              BlockInput, On
              CoordMode, Mouse, Screen
              MouseMove, 1824,80,2         ;save Bookmark
              send {LButton down}
              sleep, 50
              send {LButton up}
              CoordMode, Mouse, Screen
              MouseMove, 1824,354,0        ;cursor upper RH side of webpage
              BlockInput, Off
           }
        }
} else {
        CoordMode, Mouse, Screen           ;moves cursor over "Dark Mode" on / off switch
        MouseMove,1857,51,0
        send {LButton down}                ;cycles "Dark Mode" on / off
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen           ;moves cursor 1"x 6" down RH top of screen
        MouseMove,1860,350,0
}
return
Works like a charm :dance:

Alternate I used for about 10 minutes.. lol

Code: Select all

$MButton::
{
        CoordMode, Mouse, Screen
        MouseMove, 1788,48,2
        sleep, 500
        send {LButton down}
        sleep, 50
        send {LButton up}
        {
           keywait, MButton
           {
              sleep, 250
              CoordMode, Mouse, Screen
              MouseMove, 1824,80,2
              send {LButton down}
              sleep, 50
              send {LButton up}
              sleep, 250
              CoordMode, Mouse, Screen
              MouseMove, 1824,354,0
           }
        }
}
return

Code: Select all

$XButton2::
keywait,XButton2,t.2
if (errorlevel) {
         send {XButton2 down}
         sleep, 50
         send {XButton2 up}
} else {
      CoordMode, Mouse, Screen
      MouseMove,1857,51,0
      send {LButton down}
      sleep, 50
      send {LButton up}
      CoordMode, Mouse, Screen
      MouseMove,1860,350,0
}
return
Since I don't often cycle Dark Mode and use webpage forward VERY rare, an else/if for XButton was a fine alternate solution

I do appreciate your input on this, so go forth an code, my friend :D

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Post Reply

Return to “Ask for Help (v1)”