I am trying to put a input field next to the user's coordinates. During the process, I ran into two problems: firstly, i want the input box to be display: none till the user clicks a key, it didn't work since after clicking the key and setting the display of the box to absolute, it didn't appear. Secondly, i am trying to get the user coordinates without an event (I have that judgement because I don't want that to oblige the user to (mousemove or any other mouse events).
var inputCommand = document.querySelector('.command');
document.addEventListener('keypress', keyPressFunction);
function keyPressFunction(e) {
inputCommand.style.display = "absolute"; // this does't work
inputCommand.style.top = "100px"; // this should be replaced with the user's coordinates
inputCommand.style.left = "500px"; // this should be replaced with the user's coordinates
}
<input type="text" class="command">