Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30206

Re: Convoluted key events

Newsgroups comp.lang.javascript
Date 2016-04-03 11:17 -0700
References (1 earlier) <83594e86-16d2-4b87-91f5-29020d87bb10@googlegroups.com> <a1e90ac9-eb10-4f58-877a-cff6804d1eec@googlegroups.com> <beac24f5-2e69-4528-9c52-30f506a4acb6@googlegroups.com> <639ae4a2-e1f1-478a-bc95-5f5c5769fdf1@googlegroups.com> <9290ad47-7162-451e-9cb1-093492fffabb@googlegroups.com>
Message-ID <89be04cc-1e71-4099-ab71-e17b97021bdb@googlegroups.com> (permalink)
Subject Re: Convoluted key events
From jonas.thornvall@gmail.com

Show all headers | View raw


Den söndag 3 april 2016 kl. 19:53:57 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 19:16:28 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 18:52:55 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 3 april 2016 kl. 18:32:38 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den söndag 3 april 2016 kl. 18:19:40 UTC+2 skrev jonas.t...@gmail.com:
> > > > > Den söndag 3 april 2016 kl. 18:15:41 UTC+2 skrev jonas.t...@gmail.com:
> > > > > > I try to grip and understand javascript key events, but i fail miserably. 
> > > > > > It may seem that i try to do a double RNG, but i want to generate a steady flow and take the value that is generated into myval at the time i press the key. 
> > > > > > 
> > > > > > However not even my function call to the random function work, a hint or an example, there certainly something i do not understand about the listeners function. I would like it to loop and wait for 1000 keypress generating 1000 values of 0 and 1. 
> > > > > > 
> > > > > > But not just 1000 random values, i want the function to be called in a loop generating values but i want the value generated as i press the key.
> > > > > > 
> > > > > > I remember doing this in Basic it was very simple.
> > > > > 
> > > > > <script>
> > > > > document.onkeyup = getKey;       
> > > > > 
> > > > > function getKey() {
> > > > >     // If the users hits 'a', stop loopcode from running.
> > > > >     if(event.keyCode == 65){
> > > > >         window.clearInterval(interval);
> > > > >         document.write("test ",myval);
> > > > >     };
> > > > > }
> > > > > 
> > > > > function random (low, high) {
> > > > >       binary=Math.floor(Math.random() * (max - min + 1)) + min;
> > > > >       return binary;
> > > > > }
> > > > > 
> > > > > myval=0;
> > > > > var interval = setInterval(function() {
> > > > >      // loopcode here
> > > > >      low=0;high=1;
> > > > >      myval=random(low,high);
> > > > > }, 0);
> > > > > 
> > > > > </script>
> > > > 
> > > > And why " document.onkeyup = getKey;" isn't  "document.onkeyup = getKey();" is also weird?
> > > 
> > > Found some mismatch...
> > > <script>
> > > document.onkeyup = getKey;       
> > > 
> > > function getKey() {
> > >     // If the users hits 'a', stop loopcode from running.
> > >     if(event.keyCode == 65){
> > >         window.clearInterval(interval);
> > >         document.write("test ",myval);
> > >     };
> > > }
> > > 
> > > function random (min, max) {
> > >       binary=Math.floor(Math.random() * (max - min + 1)) + min;
> > >       return binary;
> > > }
> > > 
> > > myval=0;
> > > for(x=0;x<1000;x++){
> > > var interval = setInterval(function() {
> > >      // loopcode here
> > >      low=0;high=1;
> > >      myval=random(low,high);
> > > }, 1);
> > > }
> > 
> > ?
> > <script>
> > document.onkeyup = getKey;       
> > 
> > function getKey() {
> >     // If the users hits 'a', stop loopcode from running.
> >     if(event.keyCode == 65){
> >         window.clearInterval(interval);
> >         document.esp.bin.value+=myval;
> >        // document.write("jonas");
> >     };
> > }
> > 
> > function random (min, max) {
> >       binary=Math.floor(Math.random() * (max - min + 1)) + min;
> >       return binary;
> > }
> > 
> > interval=1;
> > myval=0;
> > var interval = setInterval(function() {
> >      // loopcode here
> >      low=0;high=1;
> >      myval=random(low,high);
> > }, 1);
> > 
> > 
> > 
> > </script>
> > <HTML><BODY>
> 
> I got something working in chrome, firefox complains event not defined.
> But i do not think what come out is random?
> 
> 
> <script>
> document.onkeyup = getKey;       
> 
> function getKey() {
>     // If the users hits 'a', stop loopcode from running.
>     if(event.keyCode == 65){
>         window.clearInterval(interval);
>         document.esp.bin.value+=binary.slice(-1);
>        // document.write("jonas");
>     };
> }
> 
> interval=1;
> min=0;max=1;
> binary="";
> for (x=0;x<1000;x++){
> interval = setInterval(function() {
>      // loopcode here
>      binary+=Math.floor(Math.random() * (max - min + 1)) + min;
> }, 0);
> }
> 
> 
> </script>
> //<HTML><BODY>
> //<FORM NAME="esp"> 
> //GENERATED VALUES<br>
> //<TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA></FORM> 
> //</BODY></HTML>

This really can't be random 1110001101111101100100001011111111110101000010110011100011111110110100100111001000000011010 and i did move  binary=""; into the loop.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:15 -0700
  Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:19 -0700
    Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:32 -0700
      Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:52 -0700
        Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 10:16 -0700
          Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 10:53 -0700
            Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 11:17 -0700
            Re: Convoluted key events "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-04-03 12:20 -0700
              Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 13:49 -0700
                Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 13:59 -0700
                Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 21:44 -0700
                Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 22:07 -0700
                Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-04 03:00 -0700
  Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-04 03:20 -0700

csiph-web