Single character input with wake state

Back in college I wrote a game where the computer would sleep for 1 second, wake up and check to see if anything needed to be processed. Of course, if the user entered a single character command, it would respond immediately.

Is there a way to do that with JavaScript?

-------------Problems Reply------------

setTimeout() and setInterval() will allow you to execute some code at regular intervals.

You can also monitor key press events in the DOM. Libraries like jQuery make this really easy with built in support for keyDown, keyUp and keyPress events. You can see these here: http://docs.jquery.com/Events

function processKeyCommand(){
...
}

document.onkeypress = processKeyCommand

function processEverythingEveryOneSecond(){
...
setTimeout(function(){processEverythingEveryOneSecond()}, 1000)
}

processEverythingEveryOneSecond()

:))

Category:javascript Views:0 Time:2009-07-15
Tags: javascript

Related post

  • How do i read single character input from keyboard using nasm (assembly) under ubuntu? 2010-07-22

    I'm using nasm under ubuntu. By the way i need to get single input character from user's keyboard (like when a program ask you for y/n ?) so as key pressed and without pressing enter i need to read the entered character. I googled it a lot but all wh

  • Catching single-character input on stdin while outputting to stdout in Python 2010-05-20

    I'm writing a simple dual timer in Python. (I'm running Linux, and this should only need to run on my system.) The idea is that the script has two separate timers, one of which is running at any one time. The user should be able to press a button to

  • how to read just a single character in shell script 2012-01-04

    I want similar option like getche() in c. How can i read just a single character input from commandline. Using read command can we do it? --------------Solutions------------- In ksh you can basically do: stty raw REPLY=$(dd bs=1 count=1 2> /dev/nu

  • PHP CLI: How to read a single character of input from the TTY (without waiting for the enter key)? 2010-09-10

    I want to read a single character at-a-time from the command line in PHP, however it seems as though there is some kind of input buffering from somewhere preventing this. Consider this code: #!/usr/bin/php <?php echo "input# "; while ($c = fread(S

  • Is it possible to read a single character from an input stream? 2012-04-18

    I started with an InputStreamReader, but this buffered its input, reading more than was required from the input stream (as mentioned in its Java docs). Delving into the source code (java version "1.7.0_147-icedtea") I got to the sun.nio.cs.StreamDeco

  • c++ outputting and inputting a single character 2009-02-20

    I am writing a program in c++ which implements a doubly-linked list that holds a single character in each node. I am inserting characters via the append function: doubly_linked_list adam; adam.append('a'); This function is implemented as follows: //A

  • Single character console input in java/clojure 2010-07-11

    How can I read a single character/key from the console without having to hit Enter? There is an old entry in Sun's bug database claiming that it can't be done in pure java. I've found these approaches JNI JLine [http://jline.sourceforge.net/] Javacur

  • Python read a single character from the user 2009-02-04

    Is there a way of reading one single character from the user input? For instance, they press one key at the terminal and it is returned. Sort of like getch(). I know that there is a function in windows for it, but I'd like something that is cross-pla

  • Is there any benefit to using char instead of string for single-character values? 2009-06-09

    For .NET fields and properties that by definition only contain a single character, is there any benefit to defining them as char instead of string? Or is that an incorrect use of the char data type? I'm thinking of a field that can hold an M or F for

  • Why doesn't my string equality test for a single character work? 2009-06-24

    How does one compare single character strings in Perl? Right now, I'm tryin to use "eq": print "Word: " . $_[0] . "\n"; print "N for noun, V for verb, and any other key if the word falls into neither category.\n"; $category = <STDIN>; print "ca

  • Is there a way to force just a single character from the onscreen keyboard 2010-04-13

    I'd like to invoke the Android onscreen keyboard to just retrieve a single character. Is there a way to do this? I am working on a hangman application and need to take input one character at a time. The plan is to have a text area for each guessed le

  • taking a character input in python from a file? 2010-05-03

    in python , suppose i have file data.txt . which has 6 lines of data . I want to calculate the no of lines which i am planning to do by going through each character and finding out the number of '\n' in the file . How to take one character input from

  • How to pick up a single character from a string using Java? 2010-07-23

    For example, "this is yahoo answers", from here I want to pick up each single character and convert it into its ASCII value. How can I do it? --------------Solutions------------- Your question is a bit vague, but probably you meant to want this? for

  • Menu that accepts single character in C language 2010-11-28

    I want to create a simple menu in C program that accepts single character. The menu will be like this: [S]how [E]xit If the user enter '1','s' or 'S' the program will print "Hello" and prompt again for the input else if the user enters '2',E or 'E' t

  • How can I test whether a single character is lower case in PHP? 2011-03-10

    I want to implement a small routine that generates the plural form of the name of an entity in Spanish. Basically, it takes a WordInCSharpCase or a wordInJavaCase, such as MedioDePago (payment method), and it appends an "s" at right before the first

  • Can't match single character in Alex grammar 2011-07-06

    I finally got back to fleshing out a GitCommit message mode that I want to add to YI but I seem to missing something basic. I can't seem to match a single character in a grammar, all my rules only work if they match the entire line. I know this has t

  • Add one space after every two characters and add a character infront of every single character 2011-07-07

    I want to add one space after every two characters, and add a character in front of every single character. This is my code: string str2; str2 = str1.ToCharArray().Aggregate("", (result, c) => result += ((!string.IsNullOrEmpty(result) && (

  • Visual basic turning array integers (x) into x amount of a single character 2012-03-31

    I have been tasked to create a Visual Basic console script that asks the user 5 times in a row to input a number into an array (sales figures in thousands), Then you display these results as a sort of tally chart. For example for the data: sales(10,7

  • accepting only character input in text box 2012-04-02

    How to validate input box for only text input using jquery and php e.g name _ must accept only text input and no special character like "[email protected] or @@@ aaaa" and alpha numeric like "aaa123" --------------Solutions------------- Ideally you want both jque

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.107 (s). 11 q(s)