Fastkeys overwriting not inserting in Win7 File Save dialog

Discussion, questions and support.
Post Reply
procrastinator
Posts: 15
Joined: Apr 1st, ’20, 22:16

Post by procrastinator » Apr 9th, ’20, 15:51

Starting to get to grips with Fastkeys. I am trying to make a generic date add shortcut and thought I had nailed it after getting your Input Selection Form macros to work with my code. My code works fine in a text file but if I use it to insert a date into the Win7 file save dialog it wipes the string already in the File Name box in the dialog and pastes the (correct) date in its place. What it should have done is to insert the date into the existing string.

This is a different behaviour from when I use a specific shortcut to trigger a macro generated by Fastkey's More>Macros>Date and Time utility for a specific date. This always inserts the result into the File Name box in the Win7 file save dialog correctly.

Why is the result different? What am I doing wrong?

The code I have written is very simple: it picks up the NoOfDays to move and the OutputFormat for the found Datestring from an Input Selection Form, does the math and sends the answer. The text Expander shortcut is type "Send" for which it substitutes "%SELECT__NoOfDays%%SELECT__OutputFormat%%CODE_DaysToAdd%" (the select variables being prefixed with "_" to stop them sending their result per your forum post 22/05/2017).

I have the same problem with the generic end of any month macro I have developed.

Code: Select all

Datestring := ""
DaysToAdd := SELECT__NoOfDays
DateStringFormat := SELECT__OutputFormat

	Datestring := A_YYYY A_MM A_dd ;set to today as YYYYMMDD

	; Use EnvAdd to add/subtract no of days
	EnvAdd, Datestring, %DaysToAdd%, Days

	;exit if date to be found is outside date arithmetic parameters 
		;Limits are: 01 Jan 1601 to 31 Dec 9999
	If Datestring not between 16010101000000 and 99991231000000
		MsgBox, 16, , The number of days deducted or added is too many and would result in a date before January 1601 or after December 1999 which is not supported by the date arithmetic. The program will now exit.
		IfMsgBox OK
			Exit
		else

		FormatTime, Dateformatted, %Datestring%, %DateStringFormat%

Send %Dateformatted%
return
procrastinator
Posts: 15
Joined: Apr 1st, ’20, 22:16

Post by procrastinator » Apr 13th, ’20, 16:26

After trying a number of alternatives it seems that the problem with the "Save As" dialog lies with the use of input forms, whether these are ahk input forms or Fastkeys Input selection forms. When drawn on screen the forms change the File Name control of the "Save As" dialog so that all text already in the File Name control is selected. The sending of anything from Fastkeys (or pressing any key) then over-writes whatever is in the File Name box.

What was required was that the Send command in Fastkeys insert a date or text at the input cursor placed in the text already in the File Name control but this behaviour with input forms prevents it by selecting all the text thus losing the cursor position and setting it up to be deleted by sending anything.

By contrast, any text or date sent by Fastkeys using hard-written code (no input forms) works fine, the text or date is inserted at the cursor position in the File Name control.

Any text or date inserted into documents works fine whether input forms are used or not. It is just the File Name control which gives the problem. Unfortunately this is my most frequent use of the function... ...

Assuming this is a default behaviour for Windows Save As dialogs I can think of only two ways round it;

1) Change the macro to send to Clipboard then re-select the insertion point and manually paste from Clipboard.
Problem: It is inconvenient for use with documents.

2) Accept that the world is imperfect and the output cannot be inserted at the cursor position in the File Name control, so have it inserted at the start of the filename instead. The cursor can be reintroduced at the start of the text by introducing the command "{home}" before the "%CODE_ ... " in the Text Expander "Substitute" box. This works because the text is deselected by moving the cursor to the home position.
Problem: Its not what I was trying to do.

Do you see a better way?
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Apr 14th, ’20, 11:51

It looks like the Windows file dialog automatically re-selects the file name after the window is re-focused.
Try the following:
- open Notepad, Save as..., click to put the cursor to the end of the name - the file name is not selected
- click/select another window and then select a Save as dialog window again - the full name is selected.

As you said, add {Home} to simulate pressing the Home button before pasting the result. Why is this a problem?
procrastinator
Posts: 15
Joined: Apr 1st, ’20, 22:16

Post by procrastinator » Apr 14th, ’20, 20:10

It is a problem because I want files sorted by Correspondent name>Date>Topic and having Date at the start of the file name does not do this. Your question is a good one though and prompted me to think harder and find a solution that works for me.

My file naming standard is "CorrespondentName.DateAsyyyy-MM-dd.Topic". The Topic is defined in sufficient detail to make content findable using Everything file search. Since I use camelCase for correspondent name I can use "Home" and "^Right" to move the cursor to the correct place (this is done only if in the Save As dialog: in other documents the date is sent to the cursor position).

Thank you for helping me think this through and confirming there is no better way. The final?? code is below. I will use the same method to deal with the problem in the EndOfAnyMonth routine I have written.

Code: Select all

Datestring := ""
DaysToAdd := SELECT__NoOfDays
DateStringFormat := SELECT__OutputFormat

Datestring := A_YYYY A_MM A_dd ;set to today as YYYYMMDD

; Use EnvAdd to add/subtract no of days
EnvAdd, Datestring, %DaysToAdd%, Days

;exit if date to be found is outside date arithmetic parameters 
	;Limits are: 01 Jan 1601 to 31 Dec 9999
If Datestring not between 16010101000000 and 99991231000000
		MsgBox, 16, , The number of days deducted or added is too many and would result in a date before January 1601 or after December 1999 which is not supported by the date arithmetic. The program will now exit.
	IfMsgBox OK
		Exit
	else

FormatTime, Dateformatted, %Datestring%, %DateStringFormat%

;If sending to a Save As dialog, correct to handle Windows selection of the entire file name
	;which otherwise would be fully selected and overwritten by send.
If WinActive("ahk_class #32770") ;Class Number refers to Save As window 
	SendInput {Home}^{Right}%Dateformatted% 
	;Home is required to deselect contents of File Name control, Ctrl-Right moves cursor to right of the opening name in the control before pasting. 
else

;for other documents send only the formatted date to the cursor position.
	SendInput %Dateformatted%

return
Post Reply