Script Dependent on Current Time Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Script Dependent on Current Time

Post by Alexander2 » 16 Nov 2022, 14:09

The following script is intended to display a message box when the mouse buttons are not swapped and the current time is before 8 p.m. Does anyone know why the message appears even when the current time is later than 8 p.m. (20:00)?

Code: Select all

SysGet, bswapped, 23
if (bswapped=0) and (%A_Hour%<20)
MsgBox The mouse buttons are not swapped, and it is before 8 p.m.

ThePeter
Posts: 49
Joined: 25 Oct 2022, 05:57

Re: Script Dependent on Current Time

Post by ThePeter » 16 Nov 2022, 14:30

As your if condition begins with opening parantheses, the condition is interpreted as an expression. In an expression, you should use A_Hour without the enclosing percent signs. In an expression, %A_Hour% will return an empty value, which in turn is evaluated as being smaller than 20.

User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Script Dependent on Current Time  Topic is solved

Post by SirSocks » 16 Nov 2022, 14:32

This should work...

Code: Select all

SysGet, bswapped, 23
if (bswapped=0) and (A_Hour<20)
MsgBox The mouse buttons are not swapped, and it is before 8 p.m.
Edit: Changed to "<"
Last edited by SirSocks on 17 Nov 2022, 08:43, edited 1 time in total.

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Script Dependent on Current Time

Post by RussF » 16 Nov 2022, 14:45

@SirSocks, that should be (A_Hour<20).

Russ

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Script Dependent on Current Time

Post by Alexander2 » 18 Nov 2022, 04:28

ThePeter wrote:
16 Nov 2022, 14:30
As your if condition begins with opening parantheses, the condition is interpreted as an expression. In an expression, you should use A_Hour without the enclosing percent signs. In an expression, %A_Hour% will return an empty value, which in turn is evaluated as being smaller than 20.
Thank you for the explanation. That was a small detail which I was not aware of.

Post Reply

Return to “Ask for Help (v1)”