0

I have been calling this script from a Windows batch file, to input data into a variable.

It works, but I have two problems.

  1. It does not detect the return/enter keypress in Chrome. I only have a return key, but I presume Enter returns the same code.
  2. When the input box appears is there a way to make it active, with the cursor already in the box?
<!-- :
::
@echo off
setlocal EnableDelayedExpansion

if "%~1" equ "/?" (
    echo Creates an input value window and output
    echo   the result to console or assign it to variable
    echo   if variable name is passed
    (echo()
    echo Usage:
    (echo()
    echo %~0nx [storeInputTo]
)
for /f "tokens=* delims=" %%p in ('mshta.exe "%~f0"') do (
    set "input=%%p"
)


if "%~1" equ "" (
    echo "%input%"
    endlocal
) else (
    endlocal & (
        set "%~1=%input%"
    )
)
exit /b
-->

<html>
<head><title>Enter Album Name</title></head>
<body>

    <script language='javascript' >
        window.resizeTo(650,250);
        window.moveTo((screen.width/2)-325, (screen.height/2)-125);
        function enterPressed(e){
                if (e.keyCode == 13) {
                    pipePass();
                }
        }
        function pipePass() {
            var pass=document.getElementById('input').value;
            var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
            close(fso.Write(pass));

        }
    </script>

    <input type="text" id="input" value="" size="50">
    <hr>
    <button onclick='pipePass()'>Submit</button>

</body>
</html>

Ideally, I would like:

  • Return/Enter to be detected instead of having to click Submit.
  • Cursor is to be active in input box so no need to click before typing.
Sadeed_pv
  • 513
  • 1
  • 9
  • 22
Robin
  • 3
  • 2
  • ActiveXObject is not supported by any browsers except IE – mplungjan Jul 09 '23 at 08:15
  • Please do not use the comparison operator `equ` for a string comparison in a Windows batch file. It is possible, but it is better to use the comparison operator `==` for a string comparison. See my answer on [Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files](https://stackoverflow.com/a/47386323/3074564) for a detailed description about the difference between `==` and `equ` on comparing two strings. – Mofi Jul 09 '23 at 16:21

1 Answers1

0

ActiveXObject is not supported by any browsers except IE

I suggest you set up a simple web server on your box and use a standard form submit.

Since a single field will submit on enter, you can then have

<form action="yourserverprocess">
  <input type="text" id="title" name="title" value="" />
  <input type="submit" value="Optional Submit button"/>
</form>
<script>
  window.addEventListener("DOMContentLoaded", () => {
    const field = document.getElementById("title")
    field.select();
    field.focus();
  });
</script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236