0
votes

I need a script that can do something similar that this script is doing:

~Escape:: If (A_ThisHotkey=A_PriorHotkey && A_TimeSincePriorHotkey<250) Send !{F4} return

This script sends Alt+F4 when Esc key is pressed twice fast.

I need a script that can sends keystroke when the mouse touch the right edge of the screen two times in less then a second. If the mouse touch the edge only once nothing should happen.

Anyone know if this can be implemented with autohotkey?

1
Yes, it can be implemented in AHK. You could use a loop/timer that runs very frequently and compares the current cursor position with the respective window edge. However, this algorithm would have nothing to do with code you posted, since you can't represent a "mouse-over event" with a hotkey. More importantly, I suspect the nature of this mouse gesture to be very error prone. What should happen if the user crosses the right border, and then returns back to the window (e.g. when closing the right-hand window)? And generally, what are you trying to achieve?MCL

1 Answers

1
votes

I have written a script that should answer your question. Each 10 milliseconds, we get the position of the mouse. If it was on the edge and has now moved off of it, we count that as a "tap" and start a 1 second timer (1000 milliseconds, the actual argument in the code is negative since we want it to run only once). Each tap also increments taps by one, so we can keep track of how many taps there are. At the end of the 1 second timer, we see if the user has tapped the edge of the screen twice. If so, send the Alt-F4 keystroke!

;; by default ahk gets mouse coordinates relative to the active
;; window, this sets it to use absolute coordinates
CoordMode, Mouse, Screen

;; how often to get the mouse position in milliseconds
UPDATE_INTERVAL := 10
RIGHT_EDGE      := A_ScreenWidth - 1

;; make the script run forever
#Persistent
SetTimer, WatchCursor, %UPDATE_INTERVAL%
return

WatchCursor:
    MouseGetPos, xpos
    ;; a tap is defined by touching and leaving the edge,
    ;; we don't want to count holding the mouse at the edge
    ;; as a tap
    if (prev = RIGHT_EDGE && xpos != RIGHT_EDGE) {
        taps += 1
        ; negative time means run once
        SetTimer, EdgeTimer, -1000
    }
    prev := xpos
return

EdgeTimer:
    ;; more than 2 taps are ignored
    if (taps = 2) {
        Send !{F4}
    }
    taps := 0
return