yudai / gotty

Share your terminal as a web application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check Terminal Input from JS

GeniusHub-io opened this issue · comments

I am building an educational website using Gotty and i need to detect when the enter key is pressed from within the terminal and what the command that was typed is so that I can check if my students entered the correct command.

But I cannot figure out how to do that from JS. Here is what I've tried:

$(document).on('keypress',function(e) {
    if(e.which == 13) {
        alert("Enter Pressed");
    }
});

And

$(document).ready(function(){
    $("iframe").load(function(){
        $(this).contents().on("keyup", function(event){
             if(event.which == 13) {
                  alert('You pressed enter!');
             }
        });
    });
});

But none of the above work from within the iframe in which i have placed the terminal.
How can I do this?