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


Groups > comp.lang.javascript > #30200 > unrolled thread

Convoluted key events

Started byjonas.thornvall@gmail.com
First post2016-04-03 09:15 -0700
Last post2016-04-04 03:20 -0700
Articles 14 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#30200 — Convoluted key events

Fromjonas.thornvall@gmail.com
Date2016-04-03 09:15 -0700
SubjectConvoluted key events
Message-ID<e561d1b5-5c41-46b3-93f6-69625f03348a@googlegroups.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.

[toc] | [next] | [standalone]


#30201

Fromjonas.thornvall@gmail.com
Date2016-04-03 09:19 -0700
Message-ID<83594e86-16d2-4b87-91f5-29020d87bb10@googlegroups.com>
In reply to#30200
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>

[toc] | [prev] | [next] | [standalone]


#30202

Fromjonas.thornvall@gmail.com
Date2016-04-03 09:32 -0700
Message-ID<a1e90ac9-eb10-4f58-877a-cff6804d1eec@googlegroups.com>
In reply to#30201
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?

[toc] | [prev] | [next] | [standalone]


#30203

Fromjonas.thornvall@gmail.com
Date2016-04-03 09:52 -0700
Message-ID<beac24f5-2e69-4528-9c52-30f506a4acb6@googlegroups.com>
In reply to#30202
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);
}

[toc] | [prev] | [next] | [standalone]


#30204

Fromjonas.thornvall@gmail.com
Date2016-04-03 10:16 -0700
Message-ID<639ae4a2-e1f1-478a-bc95-5f5c5769fdf1@googlegroups.com>
In reply to#30203
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>

[toc] | [prev] | [next] | [standalone]


#30205

Fromjonas.thornvall@gmail.com
Date2016-04-03 10:53 -0700
Message-ID<9290ad47-7162-451e-9cb1-093492fffabb@googlegroups.com>
In reply to#30204
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>

[toc] | [prev] | [next] | [standalone]


#30206

Fromjonas.thornvall@gmail.com
Date2016-04-03 11:17 -0700
Message-ID<89be04cc-1e71-4099-ab71-e17b97021bdb@googlegroups.com>
In reply to#30205
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.

[toc] | [prev] | [next] | [standalone]


#30207

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-04-03 12:20 -0700
Message-ID<991dd634-d462-4535-972a-e8883d339685@googlegroups.com>
In reply to#30205
On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
 > [...]

For once in your life, use jshint.com on your code before asking a question.

[toc] | [prev] | [next] | [standalone]


#30208

Fromjonas.thornvall@gmail.com
Date2016-04-03 13:49 -0700
Message-ID<e6942d88-c355-4818-8bf3-2f165778d163@googlegroups.com>
In reply to#30207
Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
>  > [...]
> 
> For once in your life, use jshint.com on your code before asking a question.

I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.

interval = setInterval(function() { // loopcode here }, 0);



Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?

To me the code make no sense, well the syntax i do not get it.
I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener? 
It isn't exactly obvious from the code that the interval even related to the keylistener?

Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?

I can explain waht i want todo in a single sentence and i can code it using basic in four lines. 
I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?

Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.

How many lines does it take todo what i describe above?
Pseudocode
myRandomVal(){
interval=0;
start.keyUP(A,interval)
while(keyUP!=32){
random=Math.floor(Math.random() * (max - min + 1)) + min; 
if(keyUP=32) {return random};
}
//clear.keyUP(A);
stop.keyUP(A);
}

for (var i=1;i<1000;i++){
out=myRandomVal();
document.write(out);
}

I mean what is the reason to make the code incomprehensible "like my failed attempt above".
Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.

[toc] | [prev] | [next] | [standalone]


#30209

Fromjonas.thornvall@gmail.com
Date2016-04-03 13:59 -0700
Message-ID<20258829-fb27-4acd-b895-5d22c833eef4@googlegroups.com>
In reply to#30208
Den söndag 3 april 2016 kl. 22:49:09 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> > On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
> >  > [...]
> > 
> > For once in your life, use jshint.com on your code before asking a question.
> 
> I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.
> 
> interval = setInterval(function() { // loopcode here }, 0);
> 
> 
> 
> Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?
> 
> To me the code make no sense, well the syntax i do not get it.
> I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener? 
> It isn't exactly obvious from the code that the interval even related to the keylistener?
> 
> Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?
> 
> I can explain waht i want todo in a single sentence and i can code it using basic in four lines. 
> I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?
> 
> Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.
> 
> How many lines does it take todo what i describe above?
> Pseudocode
> myRandomVal(){
> interval=0;
> start.keyUP(A,interval)
> while(keyUP!=32){
> random=Math.floor(Math.random() * (max - min + 1)) + min; 
> if(keyUP=32) {return random};
> }
> //clear.keyUP(A);
> stop.keyUP(A);
> }
> 
> for (var i=1;i<1000;i++){
> out=myRandomVal();
> document.write(out);
> }
> 
> I mean what is the reason to make the code incomprehensible "like my failed attempt above".
> Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.

And even my code seem convoluted naming the keyUP A but i can see it is useful if differentlisteners assigned to different keyranges.

[toc] | [prev] | [next] | [standalone]


#30211

Fromjonas.thornvall@gmail.com
Date2016-04-03 21:44 -0700
Message-ID<51e18650-48eb-4ef1-b81f-d1ac9e8c2d7a@googlegroups.com>
In reply to#30209
Den söndag 3 april 2016 kl. 22:59:34 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 22:49:09 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> > > On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
> > >  > [...]
> > > 
> > > For once in your life, use jshint.com on your code before asking a question.
> > 
> > I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.
> > 
> > interval = setInterval(function() { // loopcode here }, 0);
> > 
> > 
> > 
> > Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?
> > 
> > To me the code make no sense, well the syntax i do not get it.
> > I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener? 
> > It isn't exactly obvious from the code that the interval even related to the keylistener?
> > 
> > Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?
> > 
> > I can explain waht i want todo in a single sentence and i can code it using basic in four lines. 
> > I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?
> > 
> > Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.
> > 
> > How many lines does it take todo what i describe above?
> > Pseudocode
> > myRandomVal(){
> > interval=0;
> > start.keyUP(A,interval)
> > while(keyUP!=32){
> > random=Math.floor(Math.random() * (max - min + 1)) + min; 
> > if(keyUP=32) {return random};
> > }
> > //clear.keyUP(A);
> > stop.keyUP(A);
> > }
> > 
> > for (var i=1;i<1000;i++){
> > out=myRandomVal();
> > document.write(out);
> > }
> > 
> > I mean what is the reason to make the code incomprehensible "like my failed attempt above".
> > Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.
> 
> And even my code seem convoluted naming the keyUP A but i can see it is useful if differentlisteners assigned to different keyranges.

Yes i know sloppy
Pseudocode

function myRandomVal(){
interval=0;
random=0;
start.keyUP(A,interval)
while(keyUP(A)!=32){
if(random==0) random=1 elseif (random==1) random=0;

if(keyUP==32) {return random};
}
//clear.keyUP(A);
stop.keyUP(A);
}

for (var i=1;i<1000;i++){
out=myRandomVal();
document.write(out);
}

[toc] | [prev] | [next] | [standalone]


#30212

Fromjonas.thornvall@gmail.com
Date2016-04-03 22:07 -0700
Message-ID<7704f596-cb2a-481a-b215-66268a1592af@googlegroups.com>
In reply to#30211
Den måndag 4 april 2016 kl. 06:44:40 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 22:59:34 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 22:49:09 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> > > > On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
> > > >  > [...]
> > > > 
> > > > For once in your life, use jshint.com on your code before asking a question.
> > > 
> > > I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.
> > > 
> > > interval = setInterval(function() { // loopcode here }, 0);
> > > 
> > > 
> > > 
> > > Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?
> > > 
> > > To me the code make no sense, well the syntax i do not get it.
> > > I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener? 
> > > It isn't exactly obvious from the code that the interval even related to the keylistener?
> > > 
> > > Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?
> > > 
> > > I can explain waht i want todo in a single sentence and i can code it using basic in four lines. 
> > > I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?
> > > 
> > > Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.
> > > 
> > > How many lines does it take todo what i describe above?
> > > Pseudocode
> > > myRandomVal(){
> > > interval=0;
> > > start.keyUP(A,interval)
> > > while(keyUP!=32){
> > > random=Math.floor(Math.random() * (max - min + 1)) + min; 
> > > if(keyUP=32) {return random};
> > > }
> > > //clear.keyUP(A);
> > > stop.keyUP(A);
> > > }
> > > 
> > > for (var i=1;i<1000;i++){
> > > out=myRandomVal();
> > > document.write(out);
> > > }
> > > 
> > > I mean what is the reason to make the code incomprehensible "like my failed attempt above".
> > > Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.
> > 
> > And even my code seem convoluted naming the keyUP A but i can see it is useful if differentlisteners assigned to different keyranges.
> 
> Yes i know sloppy
> Pseudocode
> 
> function myRandomVal(){
> interval=0;
> random=0;
> start.keyUP(A,interval)
> while(keyUP(A)!=32){
> if(random==0) random=1 elseif (random==1) random=0;
> 
> if(keyUP==32) {return random};
> }
> //clear.keyUP(A);
> stop.keyUP(A);
> }
> 
> for (var i=1;i<1000;i++){
> out=myRandomVal();
> document.write(out);
> }

I reduced it a bit further
So what is wrong with this?

<script language="Javascript">
document.onkeyup = getKey;       
function getKey() {
    // If the users hits 'a', stop loopcode from running.
    if(event.keyCode == 32){
        window.clearInterval(interval);
        document.esp.bin.value+=binary;
    };
}

random=0;
interval = setInterval(function() {
     // loopcode here
     if(random==0){random=1} else if (random==1) {random=0;} 
}, 0);

for(i=0;i<1000;i++){setInterval();}
</script>

//<HTML><BODY BGCOLOR=GRAY>
//<H1>EXTRASENSORY PERCEPTION TEST</H1>
//<table border=3>
//<tr bgcolor="white"><td colspan="3">
//<b>PICK THE IMAGE TO CONCENTRATE UPON, VISUALISE IT TO APPEAR IN EMPTY //SLOT
//</td><tr><td bgcolor=white colspan="3"><b>AND NOW REACH ZEN AND PRESS //SPACE TO GENERATE THE PICTURE</b></td></tr><tr>
//<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
//<img src="happy.jpg"  alt="happy" width="200" height="200"></td>
//<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
//<img src="sad.jpg" alt="sad" width="200" height="200"></td>
//<td bgcolor=black></td>
//</tr></table>
//<FORM NAME="esp">
//GENERATED VALUES<br><TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA>
//</FORM> 
//</BODY></HTML>

[toc] | [prev] | [next] | [standalone]


#30215

Fromjonas.thornvall@gmail.com
Date2016-04-04 03:00 -0700
Message-ID<721b7fc7-0d94-4a97-a70b-ecfb57c8322d@googlegroups.com>
In reply to#30212
Den måndag 4 april 2016 kl. 07:07:17 UTC+2 skrev jonas.t...@gmail.com:
> Den måndag 4 april 2016 kl. 06:44:40 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 22:59:34 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 3 april 2016 kl. 22:49:09 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> > > > > On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > >  > [...]
> > > > > 
> > > > > For once in your life, use jshint.com on your code before asking a question.
> > > > 
> > > > I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.
> > > > 
> > > > interval = setInterval(function() { // loopcode here }, 0);
> > > > 
> > > > 
> > > > 
> > > > Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?
> > > > 
> > > > To me the code make no sense, well the syntax i do not get it.
> > > > I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener? 
> > > > It isn't exactly obvious from the code that the interval even related to the keylistener?
> > > > 
> > > > Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?
> > > > 
> > > > I can explain waht i want todo in a single sentence and i can code it using basic in four lines. 
> > > > I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?
> > > > 
> > > > Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.
> > > > 
> > > > How many lines does it take todo what i describe above?
> > > > Pseudocode
> > > > myRandomVal(){
> > > > interval=0;
> > > > start.keyUP(A,interval)
> > > > while(keyUP!=32){
> > > > random=Math.floor(Math.random() * (max - min + 1)) + min; 
> > > > if(keyUP=32) {return random};
> > > > }
> > > > //clear.keyUP(A);
> > > > stop.keyUP(A);
> > > > }
> > > > 
> > > > for (var i=1;i<1000;i++){
> > > > out=myRandomVal();
> > > > document.write(out);
> > > > }
> > > > 
> > > > I mean what is the reason to make the code incomprehensible "like my failed attempt above".
> > > > Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.
> > > 
> > > And even my code seem convoluted naming the keyUP A but i can see it is useful if differentlisteners assigned to different keyranges.
> > 
> > Yes i know sloppy
> > Pseudocode
> > 
> > function myRandomVal(){
> > interval=0;
> > random=0;
> > start.keyUP(A,interval)
> > while(keyUP(A)!=32){
> > if(random==0) random=1 elseif (random==1) random=0;
> > 
> > if(keyUP==32) {return random};
> > }
> > //clear.keyUP(A);
> > stop.keyUP(A);
> > }
> > 
> > for (var i=1;i<1000;i++){
> > out=myRandomVal();
> > document.write(out);
> > }
> 
> I reduced it a bit further
> So what is wrong with this?
> 
> <script language="Javascript">
> document.onkeyup = getKey;       
> function getKey() {
>     // If the users hits 'a', stop loopcode from running.
>     if(event.keyCode == 32){
>         window.clearInterval(interval);
>         document.esp.bin.value+=binary;
>     };
> }
> 
> random=0;
> interval = setInterval(function() {
>      // loopcode here
>      if(random==0){random=1} else if (random==1) {random=0;} 
> }, 0);
> 
> for(i=0;i<1000;i++){setInterval();}
> </script>
> 
> //<HTML><BODY BGCOLOR=GRAY>
> //<H1>EXTRASENSORY PERCEPTION TEST</H1>
> //<table border=3>
> //<tr bgcolor="white"><td colspan="3">
> //<b>PICK THE IMAGE TO CONCENTRATE UPON, VISUALISE IT TO APPEAR IN EMPTY //SLOT
> //</td><tr><td bgcolor=white colspan="3"><b>AND NOW REACH ZEN AND PRESS //SPACE TO GENERATE THE PICTURE</b></td></tr><tr>
> //<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
> //<img src="happy.jpg"  alt="happy" width="200" height="200"></td>
> //<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
> //<img src="sad.jpg" alt="sad" width="200" height="200"></td>
> //<td bgcolor=black></td>
> //</tr></table>
> //<FORM NAME="esp">
> //GENERATED VALUES<br><TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA>
> //</FORM> 
> //</BODY></HTML>

I guess i just do not get the structure of your eventhandling.

<script language="Javascript">
document.onkeyup = getKey;       

function getKey() {
      var i=0;
      while(i<1000){
         if(random===0){random=1;} else if (random==1) {random=0;} 
         // If the users hits 'a', stop loopcode from running.
            if(event.keyCode == 32){
            document.esp.bin.value+=random;
            }
       i++;
      }
window.clearInterval(interval);
}

random=0;
interval = setInterval(function() {
     // loopcode here
}, 0);

</script>

<HTML><BODY BGCOLOR=GRAY>
<H1>EXTRASENSORY PERCEPTION TEST</H1>
<table border=3>
<tr bgcolor="white"><td colspan="3">
<b>PICK THE IMAGE TO CONCENTRATE UPON, VISUALISE IT TO APPEAR IN EMPTY SLOT
</td><tr><td bgcolor=white colspan="3"><b>AND NOW REACH ZEN AND PRESS SPACE TO GENERATE THE PICTURE</b></td></tr><tr>
<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
<img src="happy.jpg"  alt="happy" width="200" height="200"></td>
<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
<img src="sad.jpg" alt="sad" width="200" height="200"></td>
<td bgcolor=black></td>
</tr></table>
<FORM NAME="esp">
GENERATED VALUES<br><TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA></FORM> 
 
</BODY></HTML>

[toc] | [prev] | [next] | [standalone]


#30216

Fromjonas.thornvall@gmail.com
Date2016-04-04 03:20 -0700
Message-ID<fd7263af-097f-4637-a0a7-fb6bfc965b1b@googlegroups.com>
In reply to#30200
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.

I know it is tiresome, but is there away to explain the eventhandler that works in this dimension?

<script language="Javascript">
document.onkeyup = getKey;       

function getKey() {
            if(random==0){random=1;} else if (random==1) {random=0;} 
            // If the users hits 'space', stop loopcode from running.
            if(event.keyCode == 32){
            document.esp.bin.value+=random;
            window.clearInterval(interval);
            }
}

random=0;
interval = setInterval(function() {
     // loopcode here
     while (event.keyCode!=32){
     if(random==0){random=1;} else if (random==1) {random=0;}
     }
     evemt.keyCode=0; 
}, 0);
</script>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web