Strange Datepicker behavior

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Strange Datepicker behavior

Post by jNizM » 27 Sep 2022, 08:21

AHK: v2.0-beta.10
Win: W11 Version 22H2 (Build 22622.601)

Is this a Windows bug, AHK desired behavior (or bug) or why does the date picker open when the date is older than the current week? But only if I change this afterwards. Directly after Gui.Show() it works as it should.

Code: Select all

#Requires AutoHotkey v2.0-beta

Main := Gui(, "DateTime")
Main.MarginX := 10
Main.MarginY := 10

Main.AddText("xm ym w300 0x200", "Start Datum")
MainDT := Main.AddDateTime("xm y+3 w300 Range20201001 ChooseNone", "LongDate")

Main.OnEvent("Close", (*) => ExitApp)
Main.Show()
MainDT.Value := GetLastMonday()                 ; Changes the date quietly
OnMessage 0x0100, WM_KEYDOWN



WM_KEYDOWN(wParam, *)
{
	switch wParam
	{
		case 0x71: MainDT.Value := Today()				; F2 -> Changes the date quietly
		case 0x72: MainDT.Value := GetThisMonday()		; F3 -> Changes the date quietly
		case 0x73: MainDT.Value := GetLastMonday()		; F4 -> Changes the date and opens the date picker
	}
}



Today()
{
	return SubStr(A_Now, 1, 8) "000000"
}


GetThisMonday()
{
	WDay := FormatTime(A_Now, "WDay") - 1
	return SubStr(DateAdd(A_Now, -((WDay - 1 = -1 ? 6 : WDay - 1)), "Days"), 1, 8) "000000"
}


GetLastMonday()
{
	WDay := FormatTime(A_Now, "WDay") - 1
	return SubStr(DateAdd(A_Now, -(7 + (WDay - 1 = -1 ? 6 : WDay - 1)), "Days"), 1, 8) "000000"
}

Edit:
It looks like F4 is causing this strange behavior. Even without having set the F4 hotkey, it opens the DatePicker

Code: Select all

WM_KEYDOWN(wParam, *)
{
	switch wParam
	{
		case 0x71: MainDT.Value := Today()				; F2 -> Changes the date quietly
		case 0x72: MainDT.Value := GetThisMonday()		; F3 -> Changes the date quietly
		;case 0x73: nothing								; F4 -> Still opens the DatePicker even if not set
		case 0x74: MainDT.Value := GetLastMonday()		; F5 -> Changes the date quietly
	}
}

Edit:
It is a windows "feature".. wtf
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Strange Datepicker behavior

Post by jNizM » 27 Sep 2022, 09:31

Workaround:

Code: Select all

WM_KEYDOWN(wParam, *)
{
	switch wParam
	{
		case 0x71: MainDT.Value := Today()
		case 0x72: MainDT.Value := GetThisMonday()
		case 0x73:
			MainDT.Value := GetLastMonday()
			return false							; returning null indicates the event was consumed
	}
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Strange Datepicker behavior

Post by kczx3 » 27 Sep 2022, 14:11

Maybe this?

Function Keys The key activates edit mode. The key causes the control to display a drop-down month calendar control (pressing does this as well).

https://learn.microsoft.com/en-us/windows/win32/controls/date-and-time-picker-controls

Post Reply

Return to “Ask for Help (v2)”