How to? Function Key With INPUT

Hi,
I am using;

Code:
TCC  13.03.36   Windows XP [Version 5.1.2600]
TCC Build 36   Windows XP Build 2600  Service Pack 3

I am probably missing something simple, but am not having much success.

My goal is to allow the entry of a name, but also the ability to branch if the F4 key is used. Here is my test code;

Code:
set thename=Hello
input /E /K"[a-z][F4]" /L5 Enter a name: %%thename
if %thename eq %@char[64 54 50] echo F4

When I run this, I can enter a name, but it does not conclude the entry if I press the F4 function key. All I get is a beep. The only way to conclude the entry is to press the Enter key.

How do I get it to recognize the F4 key? Again, I am probably missing something simple.

A side note: In the help for INPUT it shows;

Format: INPUT [/C /D /E["default"] /Ln /N /P /Wn /X] [prompt] %%varname

there is no mention of the /K option, even though it is described elsewhere in the help for INPUT. When I do an INPUT /? from the console, I get;

Code:
INPUT [/C /D /E /K"keys" /Ln /N /P /Wn /X] [prompt ] %%varname

These are not consistent with each other.

Thanks from Joe
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,466
88
Albuquerque, NM
prospero.unm.edu
Makes sense to me. INPUT is intended to return a string of characters; function keys are not characters. If you want to allow the user to enter a string and also trap a function key, I think you'll need to roll your own using INKEY.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,466
88
Albuquerque, NM
prospero.unm.edu
I answered too quickly. You can accept F-keys in INPUT by defining a keystroke alias:

Code:
alias @@F4=`^e*Abort*`
set thename=Hello
input /E /K"[a-z][F4]" /L5 Enter a name: %%thename
if "%thename" eq "*Abort*" echo F4

I had no idea that TCC would expand key macros inside INPUT like that!
 
I answered too quickly. You can accept F-keys in INPUT by defining a keystroke alias:

Code:
alias @@F4=`^e*Abort*`
set thename=Hello
input /E /K"[a-z][F4]" /L5 Enter a name: %%thename
if "%thename" eq "*Abort*" echo F4

I had no idea that TCC would expand key macros inside INPUT like that!

Thankyou for that. It does indeed solve my problem. The help file for INPUT should be modified to indicate this method, since it presently says;

Code:
You can specify extended keys by enclosing their names in square brackets (within the quotes),  See Keys and Key Names for a complete listing of the key names you can use within the square brackets, and a description of the key name format.

Thus, that is why I thought that the F4 key alone, as I had indicated, would allow me to exit the INPUT.

Joe
 
May 20, 2008
11,415
99
Syracuse, NY, USA
Perhaps you could build something more flexible by looping around INKEY. For example,
Code:
UNSET key
UNSET string
INKEY /C /X %%key
DO WHILE "%key" NE "@28" .AND. "%key" NE "@62"
    SET string=%[string]%key
    INKEY /C /X %%key
ENDDO
ECHO.
IFF "%key" EQ "@28" THEN
    ECHO The string is %string
ELSE
    ECHO Input aborted
ENDIFF
 

rconn

Administrator
Staff member
May 14, 2008
12,364
150
Thankyou for that. It does indeed solve my problem. The help file for INPUT should be modified to indicate this method, since it presently says;

Code:
You can specify extended keys by enclosing their names in square brackets (within the quotes),  See Keys and Key Names for a complete listing of the key names you can use within the square brackets, and a description of the key name format.

Thus, that is why I thought that the F4 key alone, as I had indicated, would allow me to exit the INPUT.

INPUT will not return until you press enter (carriage return). That is not affected by anything you specify with /K. (The key alias Charles suggested sends an enter after the string substitution.)
 
Similar threads
Thread starter Title Forum Replies Date
vefatica Documentation Function parameters Support 0
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Joe Caverly How to? Get name of current LIBRARY function? Support 4
x13 WeekNum function? Support 3
Joe Caverly No blank line in TEXT...ENDTEXT in a LIBRARY function Support 8
cgunhouse Ctrl-C from within a library function Support 6
C email[string] function Support 10
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
Dick Johnson Using the @instr function Support 5
vefatica '}' in a library function? Support 3
D Can the argument to RETURN be a function expansion? Support 3
J Trouble with @full[] function. Support 3
Fross Quick Function Question Support 17
vefatica Quoting @Function parameters? Support 0
Joe Caverly Debugging a LIBRARY function Support 10
Steve Pitts Documentation @CAPI function summary Support 0
x13 %x$ in function Support 3
thorntonpg @eval function, interesting results any explanation? Support 3
x13 Function to get interface user-defined name? Support 10
vefatica Fixed Help @FUNCTION, missing paragraph Support 8
Mordachai Variable followed by function constantly failing... Support 5
nickles Call a complex function Support 13
M Fixed Cannot use the "Browse..." function in "Find files/text" dialogbox Support 2
R Function #IDOW returns only 2 characters Support 10
T scrput `` in alias or function Support 2
S International characters - TYPE vs %@LINE function Support 5
JohnQSmith WAD @REPEAT function Support 15
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
A pdir function usage Support 3
nikbackm FUNCTION with variable number of arguments Support 17
S %@REGQUERY function Support 1
Dan Glynhampton Documentation v15 help: Error on @TRIMALL function page Support 0
M Why doesn't this @Field function work? Support 0
fpefpe How to? user function Support 1
M Why is this function getting these results in these circumstances? Support 6
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
M How to? Just verification for what I think I know regarding "Function"... Support 4
Frank How to? need help with "function" Support 10
M How to? "Function" and "%[xxx]" Support 7
M Kind of a out-of-curiosity question re. the "Function" command... Support 5
M Simple question about "Function" command... Support 4
M Just a curiosity question related to the "Function" command... Support 2
C not sure of windows registry function use Support 2
Phileosophos The @urlencode function doesn't seem to URL encode Support 16
J issue to have "if" inside function Support 3
Frank is the search-function in VIEW working? Support 2
M Weird @Index function result... Support 7
M . and .. directories counted by @files function Support 5

Similar threads