As the name suggests, the UI_GetFileName function was designed to prompt the user to type in or browse for a file name. Although it is not a general purpose input function, since it is available in hkScript distributed with build 290 and hkScript 290.1, it can be used to prompt the user for a single line of text.
--- cut here --- function __UI_GetFileName(sTitle, sPrompt, sFilter, sDefExt, sDefFileName) { var sResult = "", pIN = 0, pOUT = 0; sResult = NULL; pIN = hkp_DataNew(); pOUT = hkp_DataNew(); hkp_DataAdd(pIN, "FUNC_NAME", "UI_GetFileName"); hkp_DataAddInt(pIN, "FUNC_PARAM1", 0); hkp_DataAdd(pIN, "FUNC_PARAM2", sDefFileName); hkp_DataAdd(pIN, "FUNC_PARAM3", sTitle); hkp_DataAdd(pIN, "FUNC_PARAM4", sPrompt); hkp_DataAdd(pIN, "FUNC_PARAM5", sFilter); hkp_DataAdd(pIN, "FUNC_PARAM6", sDefExt); if(hkp_Func(pIN, pOUT)) { if(hkp_DataGetInt(pOUT, "FUNC_PARAM1", 0)) { var sFileName = ""; if(hkp_DataGet(pOUT, "FUNC_PARAM2", &sFileName)) { sResult = sFileName; } } } hkp_DataFree(pOUT); hkp_DataFree(pIN); return sResult; } { var sInput = "", sFileFilter = "All Files (*.*)|*.*"; // get some input sInput = __UI_GetFileName( "Caption", "Prompt:", sFileFilter, "", "" ); // show input Alert( sInput, "You Entered:" ); } --- cut here ---
This solution requires the use of an external hkScript module. Since support for external modules was added in hkScript 290.1, this method is not backward compatible with hkScript distributed with build 290.
First download and install the hksGUI module using the "Tools | Install | Plugin" main menu option (do not unzip, install the *.zip file to preserve the directory structure). The Delphi source code used to create the hksGUI module is available here.
Use the following code to invoke the InputBox function implemented in the hksGUI module:
--- cut here --- { // load the hksGUI module and refer to it as "gui" if( use( "hksGUI", "gui" ) ) { var sInput = ""; // get input sInput = gui.InputBox( "InputBox", "Your name:" ); // show input Alert( sInput, "You entered:" ); } } --- cut here ---