function initvkeyboard(){
var chars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",]
for(var i = 0; i < chars.length; i++){
$("#kbtnlist").append("<div class='kbtn' onclick=typechar('"+chars[i]+"')>"+chars[i]+"</div>")
}
}
I am making a crossword game this is a javascript function which accepts the input from the popup and displays it. Instead of it i want to give keyboard access to this game how do i make this function to get user input instead from my keyboard and not print the popup
function initvkeyboard(){
Window.location = ""+ input.value;
for(var i = 0; i<input; i++){
$("#kbtnlist").append("<div class='kbtn' onclick=typechar('"+chars[i]+"')>"+chars[i]+"</div>")
}
}
this is what i am trying to do i want to give keyboard access to my crossword game and not give popup
2
Answers
You could add a key-down listener on the document level:
Here is a demo:
You can add an event listener to the document to capture keyboard input. Then you can check if the pressed key is a letter (a-z) and then call your
typechar
function.Here is the updated code: