Do things using the edge Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 08:33

I finally figured out... But still have a problem: I'm using mouse coordinates to close tabs; the issue is it does in rapid series (it can close 10 tabs in few seconds and I do not want this). How can I set it to close a tab and then wait until a move again to that position?

My running code:

Code: Select all

#NoTrayIcon
#SingleInstance force
#Persistent
CoordMode, Mouse, screen
browserList := ["ahk_exe chrome.exe", "ahk_class MozillaWindowClass", "ahk_exe msedge.exe", "ahk_exe brave.exe"]
SetTimer, Check, 500
Return

Check:
MouseGetPos, xpos, ypos
for _, browser in browserList{
    If (WinActive(browser)) && (ypos < 18 && xpos > 1890){
        Send, ^w
        sleep, 1000
    }
}
Return
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 09:30

You can track the last (previous) zone, and only execute the action if the zone has changed from the previous one. See the original script for an example of that.

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 09:35

please, can you help me implement it? your original script is very useful but too advanced for a newbie like me

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 09:40

At the end of your timer, you can add a variable like, If position is... then last := True Else last := False.

Next, at the start of your timer, you add a condition like, If position is... AND last != True, then execute.

The effect would be that the execution happens only if the position is correct and the last position was not True. You are just looking for a change in position according to the position criteria that you set.

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 10:34

please give me more hints...

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 10:57

Concept:

1. Identify the cursor position's zone.
2. Determine whether the zone has changed (differs from lastZone).
3. Act based on #1 and #2.
4. Save the zone as "lastZone" for the next timer iteration.

In your timer:

1. Identify the current zone: If xpos.... then zone := ___ [some number] Else If xpos.... then zone := _____ ...
2. If (zone = ___ && lastZone != zone) then ____ [action]
3. lastZone := zone

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 11:13

Since my script is not based on a certain position but on a range (x and y have to be > than certain values), how can I set a lastzone?

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 11:21

You are right.

1. Use the range to identify a specific zone number corresponding to that range: If xpos < .... AND ypos < .... then zone := ______.
2. At the end of the timer loop, save the zone number by assigning it to lastZone.

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 13:04

Is it fine?

Code: Select all

#NoTrayIcon
#SingleInstance force
#Persistent
CoordMode, Mouse, screen
browserList := ["ahk_exe chrome.exe", "ahk_class MozillaWindowClass", "ahk_exe msedge.exe", "ahk_exe brave.exe"]
SetTimer, Check, 500
Return
If ypos < 18 && xpos > 1890 zone := 4
lastZone := zone

Check:
MouseGetPos, xpos, ypos
for _, browser in browserList{
    If (WinActive(browser)) && (ypos < 18 && xpos > 1890){
        Send, ^w
        sleep, 1000
    }
}
Return

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 13:29

Now you're coding!

Could try something like this (adjust as needed).

Code: Select all

#Persistent
CoordMode, Mouse
SetTimer, Check, 500
Check:
browsing := False
For _, browser in ["chrome", "firefox", "msedge", "brave"]
 If WinActive("ahk_exe " browser ".exe")
  browsing := True
If !browsing
 Return
MouseGetPos, xpos, ypos
If (ypos < 18 && xpos > 1890)
 zone := 4
Else zone := 5
If (zone = 4 && zone != lastZone)
 Send ^w
lastZone := zone
Return

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 28 Dec 2020, 13:55

Tried your script but it still closes 10 tabs in 2 seconds :cry:

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 28 Dec 2020, 18:27

It's just an example. You might have to adjust coordinates, etc. Do you have other scripts running?

This timer loop would only run 4-5 times in two seconds, right?

iokinjormet
Posts: 26
Joined: 07 Dec 2020, 15:01

Re: Do things using the edge

Post by iokinjormet » 29 Dec 2020, 04:14

I have the previous script running. But I don't understand your question. I mean I want to close 1 tab with 1 mouse gesture/moving.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Do things using the edge

Post by mikeyww » 29 Dec 2020, 07:27

I tested the script, seems to work as expected here.

I don't see how the loop would run ten times in two seconds, since the timer loop is 500 ms.

Ways to debug:

1. Are any other scripts also running?
2. Is this the entire script?
3. Is the script exactly the same as the one shown?
4. Have you saved and reloaded the script?
5. You could add a beep or a log file or counter (for example) to determine how many times the loop runs.
6. You could add a tooltip to see what your coordinates are. How do they compare to the coordinates in the script?
7. How did you determine the coordinates in the script?

rbhall52
Posts: 3
Joined: 03 Feb 2016, 18:51

Re: Do things using the edge

Post by rbhall52 » 08 Jan 2021, 12:36

I tried your code line, "browsers = chrome|firefox", changing it to "browsers = msedge|firefox" as the first line in my code that inserts text I select into a browser edit box, and it worked like a charm with the newest version edge browser! I could not believe the fix could be that simple, because I have previously read about extra software you have to install to get autohotkey to work with the edge browser, but your fix works great. Thanks for that code line and kudos to you for your insight :) . This should be published for everyone using autohotkey that wants to use the edge browser.

Post Reply

Return to “Ask for Help (v1)”