Numeric-input-only DateTime Control

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Numeric-input-only DateTime Control

16 Aug 2017, 16:45

Hello there.

I am trying to get a DateTime control to accept a date that has been typed using numbers only (in example, to select 03/07/2017 in the control i whant it to accept the user typing 03072017 instead of requiring something like 03{RightArrow}07{RightArrow}2017. I also need the control to understand when the user has finished the input and to move for the next control automatically.

Here is my solution thus far. It works, but there are some issues (such as users clicking the fields or using the left/right arrows in the control sometimes causing the algorithm to misbehave).

Code: Select all

#SingleInstance, Force

Gui, Font, s14
Gui, Add, DateTime, gFLUID_INPUT x30 y110 w160 vDATA_ATE
Gui, Add, DateTime, gFLUID_INPUT2 x210 y110 w160 vDATA_ATE_2
Gui, Add, Button, x150 y160 w100, To Focus
Gui, Show, w400 h300
Return

FLUID_INPUT:
FLUID_DATE_INPUT()
Return

FLUID_INPUT2:
FLUID_DATE_INPUT()
Return

FLUID_DATE_INPUT()
{
	Static OLD_DATE_CHECK
	Static LAST_CHANGE_IN_DATE
	If (!(%A_GuiControl% = OLD_DATE_CHECK))
	{
		If !(SubStr(%A_GuiControl%, 8, 1) = SubStr(OLD_DATE_CHECK, 8, 1))
		{
			LAST_CHANGE_IN_DATE := 1
			Send {Right}
		}
		Else If !(SubStr(%A_GuiControl%, 6, 1) = SubStr(OLD_DATE_CHECK, 6, 1))
		{
			LAST_CHANGE_IN_DATE := 2
			Send {Right}
		}
		Else if !(SubStr(%A_GuiControl%, 4, 1) = SubStr(OLD_DATE_CHECK, 4, 1))
		{
			Send {Right}
			Send {Tab}
		}
		OLD_DATE_CHECK := %A_GuiControl%
	}
	Else
	{
		If (LAST_CHANGE_IN_DATE = 1)
		{
			Send {Right}
			LAST_CHANGE_IN_DATE := 2
		}
		Else if (LAST_CHANGE_IN_DATE = 2) OR (LAST_CHANGE_IN_DATE = "")
		{
			Send {Right}
			Send {Tab}
		}
	}
}
Return
I would like to avoid something that does not look aesthethically professional (like 3 edit controls between /) if possible. Does anyone know of a more reliable way to achieve this in AutoHotkey?

Best wishes.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 361 guests