The keys below work in a dialog, where the dialog manager moves the input focus with Tab and Shift+Tab and uses Enter and Escape for its default and Cancel buttons, and in any other window. The controls take the keys they need from the dialog manager (WM_GETDLGCODE), so a key listed here reaches the control even in a dialog, unless it says otherwise.
With segment editing (SFTDATE_EDIT_SEGMENTS, the default):
| Key | Action |
|---|---|
| Digits | Type the number of the part being edited, also digits of other scripts such as Arabic-Indic and full-width digits (see Editing). |
| Letters | Choose a month shown as a name by its first letters, and AM or PM by the first letter of the designator. |
| Separator characters (/ . - : , space) | Complete the part being edited and move to the next part. The culture's date and time separators and the literal characters of the format are separators as well. |
| Up, Down | Change the part being edited by one. |
| + (main keyboard or numeric keypad), - (numeric keypad) | Change the part being edited by one. |
| Left, Right | Move to the previous or next part (the next or previous part with the right-to-left layout). |
| Home, End | Move to the first or last part. |
| Tab, Shift+Tab | Move to the next or previous part; from the last or the first part, to the next or previous control. |
| Delete, Backspace | Empty the part being edited, in a field that allows empty values (SftDate_SetAllowEmpty). |
| Space | Check or clear the check box (SftDate_SetShowCheckBox). Without a check box, Space is a separator. |
| Enter | Complete a value that has empty parts. Otherwise Enter goes to the dialog's default button. |
| Escape | Goes to the dialog's Cancel button while the dropdown is closed. |
| Ctrl+C, Ctrl+Insert | Copy the formatted value. |
| Ctrl+V, Shift+Insert | Paste a text and parse it. |
| F4 | Open the dropdown, or close it without changing the value. |
| Alt+Down, Alt+Up | Open the dropdown, or close it and accept the date or time. |
While the check box is cleared, the keys that edit the value are ignored. Space checks the box again, and the dropdown keys still work; choosing a date in the dropdown checks the box.
With free-form editing (SFTDATE_EDIT_FREEFORM), the field shows a text box:
| Key | Action |
|---|---|
| Characters, Left, Right, Home, End, Delete, Backspace, Ctrl+C, Ctrl+V and the other keys of a text box | Edit the text. Space is typed into the text, also in a field with a check box. |
| Enter | Parse the text and accept the value; then Enter goes to the dialog's default button. |
| Escape | Restore the text of the current value. When the text is unchanged, Escape goes to the dialog's Cancel button. |
| Up, Down | Accept the text and change the value by one day, or by one minute in a field showing only a time. |
| Tab, Shift+Tab | Move to the next or previous control; the text is parsed when the field loses the input focus. |
| F4, Alt+Down, Alt+Up | Open or close the dropdown, as with segment editing. |
While the dropdown is open, the keys go to the dropdown until a text is typed. After that, Space, Left, Right, Home and End edit the text, and Enter, Tab, F4, Alt+Down and Alt+Up close the dropdown and accept the typed text instead of the dropdown's selection.
The field keeps the input focus while the dropdown is open, and these keys go to the dropdown:
| Key | Action |
|---|---|
| Enter | Accept the date or time and close the dropdown. In a calendar without a time selection, the focused date is chosen; in range mode, a range whose last date was not chosen yet becomes a range of one day. |
| Escape | Close the dropdown without changing the value. |
| F4 | Close the dropdown without changing the value. |
| Alt+Up, Alt+Down | Accept the date or time and close the dropdown. |
| Tab, Shift+Tab | Switch between the calendar and the time selection. When the dropdown shows only one of them, accept the value, close the dropdown and move on as Tab and Shift+Tab do in the field. |
| Space | In the calendar, choose the focused date, as a click does. In the time selection, see below. |
| Arrow keys, Page Up, Page Down, Home, End | Move in the calendar or the time selection (see below). In the dropdown calendar of a single date, moving selects the focused date; the value changes when the dropdown is accepted. |
These keys work in an SftCalendar control and in the dropdown calendar of a field. In an SftCalendar control showing its smallest view, moving the focus selects the focused date, or starts a new range at it in range mode.
| Key | Action |
|---|---|
| Left, Right | Move to the previous or next day (month, year or decade in the larger views). The keys are swapped with the right-to-left layout. |
| Up, Down | Move to the same day of the previous or next week (one row up or down in the larger views). |
| Page Up, Page Down | Move to the same day of the previous or next month (the previous or next year in the year view, decade in the decade view and century in the century view). |
| Ctrl+Page Up, Ctrl+Page Down | Move to the same day of the previous or next year (month view). |
| Home, End | Move to the first or last day of the month (the first or last month, year or decade of the period shown in the larger views). |
| Shift with the keys above | Extend the range, in an SftCalendar control in range mode. |
| Ctrl+Up | Switch to the next larger view (year, decade, century). |
| Ctrl+Down | Switch to the next smaller view. |
| Enter | Switch to the next smaller view. In the smallest view, choose the date (NM_SFTDATE_DATEACTIVATED); in a dialog, Enter goes to the dialog's default button in the smallest view. |
| Space | Switch to the next smaller view; in the smallest view, choose the date (NM_SFTDATE_DATEACTIVATED). |
Tab and Shift+Tab move the input focus from an SftCalendar control to the next or previous control.
| Key | Time List | Clock |
|---|---|---|
| Up, Down | The previous or next time. | Up: the next value of the current step (hour, minutes or seconds). Down: the previous value. |
| Left, Right | - | Left: the previous value of the current step. Right: the next value. |
| Page Up, Page Down | The time one page up or down. | - |
| Home, End | The first or last time. | - |
| Space | Choose the time. | Move to the next step; in the last step, choose the time. |
| Enter | Accept the time and close the dropdown. | Accept the time and close the dropdown. |
The NM_SFTDATE_KEYDOWN notification is sent before a control handles a key. The SFTDATE_NMKEYDOWN structure holds the virtual key code (vk) and the modifier keys that are down (modifiers, a combination of SFTDATE_KEY_SHIFT, SFTDATE_KEY_CONTROL and SFTDATE_KEY_ALT). Setting fHandled to TRUE tells the control to ignore the key, including the character it would type.
case WM_NOTIFY:
if (((LPNMHDR) lParam)->code == NM_SFTDATE_KEYDOWN) {
LPSFTDATE_NMKEYDOWN lpKey = (LPSFTDATE_NMKEYDOWN) lParam;
if (lpKey->vk == VK_F2 && lpKey->modifiers == 0) {
SYSTEMTIME st;
GetLocalTime(&st);
SftDate_SetValue(lpKey->hdr.hwndFrom, &st); /* F2 sets the current date and time */
lpKey->fHandled = TRUE;
}
return TRUE;
}
break;