Hot Corners For Windows 10

Post your working scripts, libraries and tools
josiahayres
Posts: 2
Joined: 16 Feb 2016, 05:48
Google: +JosiahAyres

Hot Corners For Windows 10

16 Feb 2016, 06:12

This Script adds Mac and Linux Hot Corners capability to Windows 10.
This checks if the mouse is in a corner, and if it is the shortcut is fired.
It's partially based on another script that I found on the old AHK forum, but I have improved it as the old script would fire the shortcut key repeatedly if the mouse was moved to a corner and kept there.
It is also easier to reconfigure the actions in the corners because I majorly refactored the old script.

Code: Select all

#Persistent 				; Keeps script running persisitantly 
SetTimer, HotCorners, 0 		; HotCorners is name of timer, will be reset every 0 seconds until process is killed
return
HotCorners: 				; Timer content 
CoordMode, Mouse, Screen		; Coordinate mode - coords will be passed to mouse related functions, with coords relative to entire screen 

IsCorner(cornerID)
{
	WinGetPos, X, Y, Xmax, Ymax, Program Manager 		; get desktop size
	MouseGetPos, MouseX, MouseY 							; Function MouseGetPos retrieves the current position of the mouse cursor
	T = 5 												; adjust tolerance value (pixels to corner) if desired
	CornerTopLeft := (MouseY < T and MouseX < T) 					; Boolean stores whether mouse cursor is in top left corner
	CornerTopRight := (MouseY < T and MouseX > Xmax - T) 			; Boolean stores whether mouse cursor is in top right corner
	CornerBottomLeft := (MouseY > Ymax - T and MouseX < T) 			; Boolean stores whether mouse cursor is in bottom left corner
	CornerBottomRight := (MouseY > Ymax - T and MouseX > Xmax - T) 	; Boolean stores whether mouse cursor is in top left corner
	
	if (cornerID = "TopLeft"){
		return CornerTopLeft
	}
	else if (cornerID = "TopRight"){
		return CornerTopRight
	}
	else if (cornerID = "BottomLeft"){
		return CornerBottomLeft
	}
	else if  (cornerID = "BottomRight") {
		return CornerBottomRight
	}
}

; Show Task View (Open Apps Overview)
if IsCorner("TopLeft")
{
	Send, {LWin down}{tab down}
	Send, {LWin up}{tab up} 
	Loop 
	{
		if ! IsCorner("TopLeft")
			break ; exits loop when mouse is no longer in the corner
	}
}

; Show Action Center
if IsCorner("TopRight")
{	
	Send, {LWin down}{a down}
	Send, {LWin up}{a up}
	Loop
	{
		if ! IsCorner("TopRight")
			break ; exits loop when mouse is no longer in the corner
	}	
}

; Press Windows 
if IsCorner("BottomLeft")
{	
	Send, {LWin down}
	Send, {LWin up}
	Loop
	{
		if ! IsCorner("BottomLeft")
			break ; exits loop when mouse is no longer in the corner
	}	
}
dsewq1LYJ
Posts: 114
Joined: 26 Aug 2014, 23:21

Re: Hot Corners For Windows 10

17 Feb 2016, 20:11

Sir...It's really a dark corner...
Holy jesus. It is incredibly useful...
User avatar
17kimv
Posts: 37
Joined: 21 Dec 2015, 20:15

Re: Hot Corners For Windows 10

22 Feb 2016, 23:40

I found it usefull, but I have 2 monitors, and it seems to glich between them, Still works great! Probably easy way to fix it.
Look MA! I am a programmer! :superhappy:
Maik
Posts: 2
Joined: 24 May 2016, 01:26

Re: Hot Corners For Windows 10

24 May 2016, 01:28

This... is... awesome. Wow!
Maik
Posts: 2
Joined: 24 May 2016, 01:26

Re: Hot Corners For Windows 10

24 May 2016, 02:02

I did a small modification because in some cases you need do pull a windows to a corner (in case you will set window size and position to quarter screen). If so then press and hold [ctrl] while pulling the window and it will snap into position instead of bringing up desktop view, start or whatever. Maybe someone find this useful:

Code: Select all

SetTimer, HotCorners, 0 ; HotCorners is name of timer, will be reset every 0 seconds until process is killed
return
HotCorners: ; Timer content 
CoordMode, Mouse, Screen ; Coordinate mode - coords will be passed to mouse related functions, with coords relative to entire screen 

 
IsCorner(cornerID)
{
  WinGetPos, X, Y, Xmax, Ymax, Program Manager ; get desktop size
  MouseGetPos, MouseX, MouseY ; Function MouseGetPos retrieves the current position of the mouse cursor
  GetKeyState, controlKeyState, Control ; Function GetKeyState retrieves the current status ("U"p or "D"own) of a key
 
  T = 2 ; adjust tolerance value (pixels to corner) if desired
  
  if controlKeyState = U ; use hot corners only if control is not pressed
  {
    CornerTopLeft := (MouseY < T and MouseX < T) ; Boolean stores whether mouse cursor is in top left corner
    CornerTopRight := (MouseY < T and MouseX > Xmax - T) ; Boolean stores whether mouse cursor is in top right corner
    CornerBottomLeft := (MouseY > Ymax - T and MouseX < T) ; Boolean stores whether mouse cursor is in bottom left corner
    CornerBottomRight := (MouseY > Ymax - T and MouseX > Xmax - T) ; Boolean stores whether mouse cursor is in top left corner
  }
  
  if (cornerID = "TopLeft"){
    return CornerTopLeft
  }
  else if (cornerID = "TopRight"){
    return CornerTopRight
  }
  else if (cornerID = "BottomLeft"){
    return CornerBottomLeft
  }
  else if  (cornerID = "BottomRight") {
    return CornerBottomRight
  }
}
 
; Show Task View (Open Apps Overview)
if IsCorner("TopLeft")
{
  Send, #{tab}
  Loop 
  {
    if ! IsCorner("TopLeft")
      break ; exits loop when mouse is no longer in the corner
  }
}
 
; Show Action Center
if IsCorner("TopRight")
{  
  Send, #a  
  Loop
  {
    if ! IsCorner("TopRight")
      break ; exits loop when mouse is no longer in the corner
  }  
}
 
; Press Windows 
if IsCorner("BottomLeft")
{  
  Send, {LWin}
  Loop
  {
    if ! IsCorner("BottomLeft")
      break ; exits loop when mouse is no longer in the corner
  }  
}

; Show Calendar
if IsCorner("BottomRight")
{  
  Send, #b{left}{enter}
  Loop
  {
    if ! IsCorner("BottomRight")
      break ; exits loop when mouse is no longer in the corner
  }  
}
(I added calendar in lower right corner too)
killah fhonics

Re: Hot Corners For Windows 10

28 Jul 2016, 17:19

Hey guys... how or where do I apply this script?
Any tutorial online?

Let me know.
Cheers.
josiahayres
Posts: 2
Joined: 16 Feb 2016, 05:48
Google: +JosiahAyres

Re: Hot Corners For Windows 10

28 Jul 2016, 22:13

1. You need to install https://autohotkey.com/download
2. Then download the script. It will probably download as script.txt
Or you can create a new text file on your desktop and copy paste the script from the browser into the new file.
3. Rename the file to script.ahk
4. Run script.ahk (double click)
5. To make the script automatically run on PC boot, copy the script.ahk file to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

That's it!
killah fhonics

Re: Hot Corners For Windows 10

29 Jul 2016, 13:08

Thank you sir!

Didnt realize AutoHotKey was a thing.... google search brought me here.
Cheers.
t4akawolf
Posts: 12
Joined: 30 Jul 2016, 03:30

Re: Hot Corners For Windows 10

30 Jul 2016, 12:16

What do I change to make it so that it registers an actual click to activate a Hot Corner?

EDIT: Figured it out myself after a lot of research and tinkering (I'm a newb). I changed the last part of the script to this:

Code: Select all

GetKeyState, LState, LButton

; Press Windows 
if (IsCorner("TopLeft") && LState = "D")
{	
	Send, {LWin down}
	Send, {LWin up}
	Loop
	{
		if ! IsCorner("TopLeft")
			break ; exits loop when mouse is no longer in the corner
	}	
}

; Show Desktop 
if (IsCorner("BottomLeft") && LState = "D")
{	
	Send, {LWin down}{d down}
	Send, {LWin up}{d up}
	Loop
	{
		if ! IsCorner("BottomLeft")
			break ; exits loop when mouse is no longer in the corner
	}	
}

; EMPTY
;if (IsCorner("TopRight") && LState = "D")
;{	
;	Send, {...}
;	Send, {...}
;	Loop
;	{
;		if ! IsCorner("TopRight")
;		break ; exits loop when mouse is no longer in the corner
;	}
;}

; Show Action Center
if (IsCorner("BottomRight") && LState = "D")
{	
	Send, {LWin down}{a down}
	Send, {LWin up}{a up}
	Loop
	{
		if ! IsCorner("BottomRight")
		break ; exits loop when mouse is no longer in the corner
	}
}
Hope someone finds it useful. Note that the Action for TopRight is empty. Fill it in if you have a use for it (by removing the semi-colons and assigning commands to Send), or just leave it be. I didn't use that corner because it would interfere with Closing maximized windows; if you do end up using TopRight, I suggest you remove && LState = "D" from it first, and using it how OP intended it.

P.S.: If the positions and corresponding Hot Actions seem weird to anyone, it's because I have my Taskbar vertical and on the left edge of my screen. So, my Start button used to be (before I hid it, now that I have no use for it) in the top left corner, and my Show Desktop button used to be in the bottom left.
User avatar
hasantr
Posts: 770
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Hot Corners For Windows 10

03 Feb 2017, 12:57

When he goes to the corner, he works right away. Can it be done in a way that will take action after waiting a little?
Thank you. :)
Guest

Re: Hot Corners For Windows 10

10 Jan 2018, 21:03

you sir...YOU...are my hero of the month!
Thank you so much
User avatar
Delta Pythagorean
Posts: 574
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Hot Corners For Windows 10

11 Jan 2018, 10:34

I actually have a simplified version of this with customization in what it can do on my laptop, give me an hour or so and I can get it right in here!

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.19041
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Tophat Cat // Delta#8888

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
User avatar
Delta Pythagorean
Posts: 574
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Hot Corners For Windows 10

12 Jan 2018, 19:34

Here it is, the Hotcorner script that's easy to manage!
Hope you find it useful!

Code: Select all


#NoEnv
#SingleInstance, Force
#MaxThreadsPerHotkey, 1
#KeyHistory, 0
#Persistent
ListLines, Off
SetBatchLines -1
SetWinDelay, -1
SetMouseDelay, -1
SetKeyDelay, -1, -1
SetTitleMatchMode, 3
DetectHiddenWindows, On
SetWorkingDir, %A_ScriptDir%
SendMode, Input
CoordMode, Mouse, Screen

CornerList :=
(LTrim Join
	{
		"TopLeft":		"TopLeft",
		"TopRight":		"TopRight",
		"BottomRight":	"BottomRight",
		"BottomLeft":	"BottomLeft"
	}
)
SetTimer, HotCorners, 10
Return

HotCorners:
	For Each, Item in CornerList
		CheckCorner(Each, Item)
	Return

TopLeft:
TopRight:
BottomLeft:
BottomRight:
	MsgBox, % A_ThisLabel
	Return

IsCorner(CornerID) {
	Static T := 10, IsMouse := {}
	Mouse := MouseGetPos()
	IsMouse.TopLeft			:= (Mouse.Y < T) && (Mouse.X < T)
	IsMouse.TopRight		:= (Mouse.Y < T) && (Mouse.X > (A_ScreenWidth - T))
	IsMouse.BottomLeft		:= (Mouse.Y > (A_ScreenHeight - T)) && (Mouse.X < T)
	IsMouse.BottomRight		:= (Mouse.Y > (A_ScreenHeight - T)) && (Mouse.X > (A_ScreenWidth - T))

	Return, IsMouse[CornerID]
}

CheckCorner(Name, LabelOrFunc) {
	If (IsCorner(Name)) {
		If (IsLabel(LabelOrFunc))
			GoSub, % LabelOrFunc
		Else If (IsFunc(LabelOrFunc))
			%LabelOrList%(Name)
		Else
			Throw Exception("This is not a function!")
		Loop {
			If (!IsCorner(Name))
				Break
		}
	}
	Return
}

MouseGetPos(Options := 3) {
	MouseGetPos, X, Y, Win, Ctrl, % Options
	Return, {X: X, Y: Y, Win: Win, Ctrl: Ctrl}
}
EDIT: Minor changes

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.19041
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Tophat Cat // Delta#8888

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
User avatar
king-of-hearts
Posts: 30
Joined: 01 Oct 2017, 06:29

Re: Hot Corners For Windows 10

17 Jan 2018, 13:57

Cool!
https://autohotkey.com/boards/viewtopic.php?f=6&t=38707 - MS Access Manager - SQL Query: Incredible tool for MS Access/SQL Queries on the fly!!
andrewkondrat

Re: Hot Corners For Windows 10

10 Mar 2018, 11:46

With delay and example of two corners. If you restart it, then there is no duplication

Code: Select all

; Screen
CoordMode, Mouse, Screen
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
; Temp Variables
BLCounter := 0
BRCounter := 0
; Kill previous
Send {Ctrl down}{Shift down}{Alt down}{LWin down}{Ctrl up}{Shift up}{Alt up}{LWin up}
Sleep 200
; While SHIT + ALT + CTRL + LWIN pressed
While Not(GetKeyState("Ctrl", "P") And  GetKeyState("Alt", "P") And GetKeyState("LWin", "P") And GetKeyState("Shift", "P"))
	{
	; Read mouse
	MouseGetPos, MouseX, MouseY
	
	;Left corner
	If (MouseX = 0) And (MouseY = VirtualHeight - 1)
		{
		Sleep, 100
		BLCounter := BLCounter + 100
		If BLCounter >= 300
			{
			; Send key sequence
			Send, #{Tab}
			While (MouseX = 0) And (MouseY = VirtualHeight - 1)
				{
				MouseGetPos, MouseX, MouseY
				}
			}
		}
	Else
		{
		BLCounter := 0
		}
		
	If (MouseX = VirtualWidth - 1) And (MouseY = VirtualHeight - 1)					
		{
		Sleep, 100
		BRCounter := BRCounter + 100
		If BRCounter >= 300
			{
			; Send key sequence
			Send, #d
			While (MouseX = VirtualWidth - 1) And (MouseY = VirtualHeight - 1)				
				{
				MouseGetPos, MouseX, MouseY								
				}
			}
		}
	Else
		{
		BRCounter := 0
		}
	}
thegooddoctor
Posts: 8
Joined: 16 Apr 2018, 22:47

Re: Hot Corners For Windows 10

29 Nov 2020, 18:07

Excellent!
How does one configure what action is taken with each hotcorner?
(I can see where it occurs in the script, but I can't seem to customize it to preform a specific action)

Thanks!
Delta Pythagorean wrote:
12 Jan 2018, 19:34
Here it is, the Hotcorner script that's easy to manage!
Hope you find it useful!


EDIT: Minor changes
thegooddoctor
Posts: 8
Joined: 16 Apr 2018, 22:47

Re: Hot Corners For Windows 10

29 Nov 2020, 18:16

ok - I think I got it ... if there is a better way then please let me know
insert these modifications

Code: Select all

TopLeft:
	msgbox this is top left
	return
TopRight:
	msgbox this is top right
	Return
BottomLeft:
	msgbox this is bottom left
	return
BottomRight:
	msgbox this is bottom right
	Return
User avatar
Delta Pythagorean
Posts: 574
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Hot Corners For Windows 10

29 Nov 2020, 21:12

Despite being an old script, I could quickly modify it to look and work better as well as adding better customization.

Edit:
Here it is:

Code: Select all

; Example START
#NoEnv
#SingleInstance, Force
#MaxThreadsPerHotkey, 1
#KeyHistory, 0
#Persistent
ListLines, Off
SetBatchLines -1

Corners := []
	Corners.Push(New HotCorner(HotCorner.TOP_LEFT, Func("HandleCorner")))
	Corners.Push(New HotCorner(HotCorner.TOP_RIGHT, Func("HandleCorner")))
	Corners.Push(New HotCorner(HotCorner.BOTTOM_LEFT, Func("HandleCorner")))
	Corners.Push(New HotCorner(HotCorner.BOTTOM_RIGHT, Func("HandleCorner")))
Return

HandleCorner(CornerType) {
	MsgBox, % CornerType
	Return False
}
; Example END

Class HotCorner {
	Static TOP_LEFT := "TOP_LEFT"
	Static TOP_RIGHT := "TOP_RIGHT"
	Static BOTTOM_LEFT := "BOTTOM_LEFT"
	Static BOTTOM_RIGHT := "BOTTOM_RIGHT"

	__New(Corner, Callback, Range = 10, Time = 10) {
		If (HotCorner.HasKey(Corner)) {
			If (!This._IsValidCallback(Callback)) {
				Return False
			}
			This.Corner := Corner
			This.Callback := Callback
			This.Range := Range
			This.Time := Time
			This.Resume()
		} Else {
			Throw Exception("Unknown corner value", -1, Corner)
		}
		Return This
	}

	__Delete() {
		This.Pause()
		Return
	}

	_IsCorner() {
		CoordMode, Mouse, Screen
		MouseGetPos, MX, MY

		Switch (True) {
			Case ((MY < This.Range) && (MX < This.Range)):
				Return HotCorner.TOP_LEFT
			Case ((MY < This.Range) && (MX > (A_ScreenWidth - This.Range))):
				Return HotCorner.TOP_RIGHT
			Case ((MY > (A_ScreenHeight - This.Range)) && (MX < This.Range)):
				Return HotCorner.BOTTOM_LEFT
			Case ((MY > (A_ScreenHeight - This.Range)) && (MX > (A_ScreenWidth - This.Range))):
				Return HotCorner.BOTTOM_RIGHT
			Default:
				Return False
		}
	}

	_CheckCorner(Corner) {
		If (This._IsCorner() == HotCorner[Corner]) {
			Return This.Callback.Call(Corner)
		}
		Return False
	}

	_IsValidCallback(Callback) {
		Return ((IsLabel(Callback)
			|| IsFunc(Callback)
			|| (IsObject(Callback)
				&& IsFunc(Callback.Name))))
	}

	Pause() {
		IsCornerCall := ObjBindMethod(This, "_CheckCorner", This.Corner, This.Callback)
		SetTimer, % IsCornerCall, Off
	}

	Resume() {
		IsCornerCall := ObjBindMethod(This, "_CheckCorner", This.Corner, This.Callback)
		SetTimer, % IsCornerCall, % This.Time
	}
}
I'm not wanting to assume you know how to do OOP (Object Oriented Programming), but this is just about the best I could think of.
The best way to explain it is this:
To handle a new corner, say the top left, create a new instance of the class like so: Corner := New HotCorner(HotCorner.TOP_LEFT, Func("MyFunc")). With this you can control start to check if the mouse is in that corner and if you want to pause checking, use this: Corner.Pause(). Simple enough. If you have any questions, please don't be afraid to ask! :D

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.19041
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Tophat Cat // Delta#8888

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: viv and 17 guests