Sleep/shutdown pc via mouse action Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
docay
Posts: 5
Joined: 27 Sep 2022, 18:53

Sleep/shutdown pc via mouse action

Post by docay » 27 Sep 2022, 19:01

Hi! I have a simple bluetooth computer mouse (right/left button and scroll wheel) - Logitech M185. I would like to put the computer to sleep or shutdown by holding pressed both buttons (left and right) at the same time for a certain period of time e.g. 10 seconds. I wonder if it is possible and how to do it. Thank you in advance for your help.

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

Re: Sleep/shutdown pc via mouse action  Topic is solved

Post by mikeyww » 27 Sep 2022, 20:21

Welcome to this AutoHotkey forum!

Code: Select all

~LButton & ~RButton::
SetTimer, Go, -2000
SoundBeep, 1500
Return

~LButton Up::
~RButton Up::SetTimer, Go, Off

Go:
SoundBeep, 1000
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0) ; Sleep computer
Return

User avatar
docay
Posts: 5
Joined: 27 Sep 2022, 18:53

Re: Sleep/shutdown pc via mouse action

Post by docay » 27 Sep 2022, 20:42

Thank you so much! Work perfect. You are awesome :)

User avatar
docay
Posts: 5
Joined: 27 Sep 2022, 18:53

Re: Sleep/shutdown pc via mouse action

Post by docay » 29 Sep 2022, 07:42

I have a question how to modify this script so that pressing the mouse buttons works also the other way. Now the order is: ~LButton & ~RButton:: This means that I can press the left button first and keep it e.g. for 1 minute, and next add the right mouse button. The action (timer) will start only when both are pressed, but the first (starting the sequence) must be the left button (~LButton). I want the action to be executed regardless of which key starts the sequence, that is: ~LButton & ~RButton:: = ~RLButton & ~LButton:: I am asking because it happens that when the keys are pressed simultaneously, the right button is pressed by some fractions of a millisecond faster than the left button and then the action does not work. Invariably, thank you in advance for your time and help :)

User avatar
docay
Posts: 5
Joined: 27 Sep 2022, 18:53

Re: Sleep/shutdown pc via mouse action

Post by docay » 29 Sep 2022, 08:10

Of course, in the previous post it should be: ~LButton & ~RButton:: = ~RButton & ~LButton::
I can't modify a bug.

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

Re: Sleep/shutdown pc via mouse action

Post by mikeyww » 29 Sep 2022, 08:38

You can add a line to the top of the script.

Code: Select all

~RButton & ~LButton::

User avatar
docay
Posts: 5
Joined: 27 Sep 2022, 18:53

Re: Sleep/shutdown pc via mouse action

Post by docay » 29 Sep 2022, 09:07

Thank you!

Post Reply

Return to “Ask for Help (v1)”