I have been calling this script from a Windows batch file, to input data into a variable.
It works, but I have two problems.
- It does not detect the return/enter keypress in Chrome. I only have a return key, but I presume Enter returns the same code.
- 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.