<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with keyisdown() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=keyisdown%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:31:32 +0000</pubDate>
         <description>Tagged with keyisdown() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedkeyisdown%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>This is being wierd, that's the best way I can explain it</title>
      <link>https://forum.processing.org/two/discussion/27925/this-is-being-wierd-that-s-the-best-way-i-can-explain-it</link>
      <pubDate>Sun, 06 May 2018 21:16:57 +0000</pubDate>
      <dc:creator>metype</dc:creator>
      <guid isPermaLink="false">27925@/two/discussions</guid>
      <description><![CDATA[<p>I referenced p5.js and p5.dom.js and, of course, Evolution.js</p>

<p>Evolution.js:</p>

<pre><code>var img;
var X;
var Y;
var noclipspeed = 20
var Z
var shp
var shpi
var speed
var freecam = false
var XR = 0
var YR = 0
var debug = true
function preload() {
town = loadImage('./assets/town.png');
BG = loadImage('./assets/BG.png');
X = random(-250,250)
Y = random(-250,250)
Z = 1
shop = loadImage('./assets/shop.png')
hax = loadImage('./assets/hax.png')
cursor(CROSS)
}


function setup() {
 createCanvas(1905,1065,WEBGL);
}


function draw() {
  rotateY(XR)
  rotateX(YR)
  cursor(CROSS)
  keyPressed()
  translate(0,0,10000)
  texture(hax)
  plane(10000,10000)
  translate(0,0,-10000)
  translate(0,0,-10000)
  texture(BG)
  plane(10000000,1000000)
  texture(town)
  translate(0,0,10000)
  translate(X-1000,Y-1000,Z)
  plane(950,567)
  translate(800,750)
  texture(shop)
  plane(100,100)
  if(freecam === false) {
  if (Z&gt;577) {
  Z = 577
} else if (Z &lt; -2600) {
  Z = -2600
} else if (Z === 0 ) {
 Z = 1
}
}
if (shpi === 1) {
Z = 577
X = -814.219833927416
Y = -751.7183831208923
}
if (noclipspeed &lt; 10) {
noclipspeed = 10
}
}

function keyPressed() {
 if (keyIsDown(70)) {
   fullscreen(1)
} else if (keyIsDown(78)) {
   fullscreen(0)
} else if (keyIsDown(79)) {
    freecam = true
  } else if (keyIsDown(76)) {
    freecam = false
    XR = 0
    YR = 0
  } else if (keyIsDown(113)) {
saveCanvas("EvolutionTST","png")
}
 if (freecam === false) {
 XR = 0
 YR = 0
 if (keyIsDown(65)) {
    X+=10;
  } else if (keyIsDown(68)) {
    X-=10;
  } else if (keyIsDown(87)) {
    Y+=10;
  } else if (keyIsDown(83)) {
    Y-=10;
  } else if (keyIsDown(70)) {
   fullscreen(1)
  } else if (keyIsDown(78)) {
   fullscreen(0)
  }
} else {
 if (keyIsDown(65)) {
    X += noclipspeed
} else if (keyIsDown(68)) {
    X -= noclipspeed
} else if (keyIsDown(87)) {
    Z += noclipspeed
} else if (keyIsDown(83)) {
    Z -= noclipspeed
} else if (keyIsDown(32)) {
    Y += noclipspeed
} else if (keyIsDown(16)) {
    Y -= noclipspeed
} else if (keyIsDown(39)) {
    XR += 0.05
} else if (keyIsDown(37)) {
    XR -= 0.05
} else if (keyIsDown(38)) {
    YR -= 0.05
} else if (keyIsDown(40)) {
    YR += 0.05
} else if (keyIsDown(107)) {
    noclipspeed += 10
} else if (keyIsDown(109)) {
    noclipspeed -= 10
} 
}
}

function mouseWheel(event) {
   Z -= event.delta
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>use of keyPressed and keyReleased functions</title>
      <link>https://forum.processing.org/two/discussion/26199/use-of-keypressed-and-keyreleased-functions</link>
      <pubDate>Wed, 31 Jan 2018 16:42:59 +0000</pubDate>
      <dc:creator>Ekta</dc:creator>
      <guid isPermaLink="false">26199@/two/discussions</guid>
      <description><![CDATA[<p>How can I do in P5.js that if I press up key the object will goes in up direction but when I release that key it will comes in down direction?</p>
]]></description>
   </item>
   <item>
      <title>browsers who see my website for the 1st time show an older version</title>
      <link>https://forum.processing.org/two/discussion/25476/browsers-who-see-my-website-for-the-1st-time-show-an-older-version</link>
      <pubDate>Sat, 09 Dec 2017 18:17:34 +0000</pubDate>
      <dc:creator>ravel44</dc:creator>
      <guid isPermaLink="false">25476@/two/discussions</guid>
      <description><![CDATA[<p>Hi !
I reuploaded all my files to my host 12h ago. When sending my website to friends who never went to my url before, they see my old website...
Even on my Chrome browser, it keeps showing the older version unless I hit inspect and then reload by selecting "empty cache and hard load". And even if I type again my url after doing the inspect/emptycache/hardload method, it's showing the old version again.
What am I missing ?</p>
]]></description>
   </item>
   <item>
      <title>I don't know how to make obstacles in my programme</title>
      <link>https://forum.processing.org/two/discussion/25117/i-don-t-know-how-to-make-obstacles-in-my-programme</link>
      <pubDate>Mon, 20 Nov 2017 23:08:05 +0000</pubDate>
      <dc:creator>Thejotepro</dc:creator>
      <guid isPermaLink="false">25117@/two/discussions</guid>
      <description><![CDATA[<p>Hello community,
I'm a student and I have to do a final project of processing, so I decided to make an RPG Scene. I have a lot of problems and bugs (for example I don't know how to do a movement animation of the character) but I mainly want to fix the problem of the objects. I have an image (the main character) that moves with keys, and I have a cow that interacts with the character, but it doesn't make contact with the character. <img src="https://forum.processing.org/two/uploads/imageupload/314/08WJWEFIAB1K.PNG" alt="2" title="2" />
<img src="https://forum.processing.org/two/uploads/imageupload/415/0DHNKX5WBQXJ.PNG" alt="Captura" title="Captura" />
Here you have the sketch: <a href="https://www.openprocessing.org/sketch/471627" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/471627</a></p>
]]></description>
   </item>
   <item>
      <title>Help with Y axis?</title>
      <link>https://forum.processing.org/two/discussion/24748/help-with-y-axis</link>
      <pubDate>Thu, 26 Oct 2017 11:18:42 +0000</pubDate>
      <dc:creator>Nautilus</dc:creator>
      <guid isPermaLink="false">24748@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm new on the forum and I'm sorry if I somehow brake any rules.
Anyway, I'm trying to make a simple game that i found on the p5js.org website and I'm just editing it a little bit.
So you are a red ball and you can move a round on a canvas, now I want to make borders, like if you go all the way up you respawn, I managed to make those borders for the X axis, -X axis, Y axis, but I can't make it for the -Y if that's how I should say it. Here is my code:</p>

<pre><code>var x = 30;
var y = 350;
var velicina = 50;

function setup() {
    createCanvas(1366, 658);
    background(100);

}

function draw() {
  if (keyIsDown(LEFT_ARROW)) 
    x-=10;

  if (keyIsDown(RIGHT_ARROW))
    x+=10;

  if (keyIsDown(UP_ARROW))
    y-=10;

  if (keyIsDown(DOWN_ARROW))
    y+=10;


  clear();
  fill(255, 0, 0);
  ellipse(x, y, 50, 50);


    if(x &lt; 30) {
        clear();
        background(100);
        ellipse(x, y, 50, 50);
        x = 30;
        y = 350;

    }

    if(x &gt; 1340) {
        clear();
        background(100);
        ellipse(x, y, 50, 50);
        x = 30;
        y = 350;
    }

    if(y &lt; 30) {
        clear();
        background(100);
        x = 30;
        y = 350;
    }

    if(y &gt; -150){
       clear();
       background(100);
       x = 30;
       y = 350;
}
</code></pre>

<p>It just doesn't work under Y -200 or Y 200. Please, try it yourself and see.</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>Continuous input on key press in p5.js</title>
      <link>https://forum.processing.org/two/discussion/22445/continuous-input-on-key-press-in-p5-js</link>
      <pubDate>Sun, 07 May 2017 17:44:54 +0000</pubDate>
      <dc:creator>rebelL1ON</dc:creator>
      <guid isPermaLink="false">22445@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
Firstly I just want to say that I didn't know where to ask this question since I didn't found the <strong>p5.js</strong> forum so I'm asking here, I'll understand if that's not the correct place.
Anyway I'm trying to do a pong game using p5 and I'd want the paddles to move <em>continuously</em> when the user press the key (i.e UP_ARROW). I searched a bit and it seems to be possible in Processing using keyTyped() (I'm probably wrong) and I just wanted to know if that's possible in p5. If there is no equivalent, could someone give me an advice on how could I do this?</p>

<p>Thank you in advance,</p>

<p>rebelL1ON.</p>
]]></description>
   </item>
   <item>
      <title>How to move an object with arrows</title>
      <link>https://forum.processing.org/two/discussion/21438/how-to-move-an-object-with-arrows</link>
      <pubDate>Thu, 16 Mar 2017 20:27:29 +0000</pubDate>
      <dc:creator>alexjilavu17</dc:creator>
      <guid isPermaLink="false">21438@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I've just started p5 programming and I'm really into it , but I can't figure out how to move an object with direction arrows.
    <code>function setup(){
        createCanvas(1250,1000);
        bug = new obj();
    }</code>
    <code>function draw(){
        background(50,89,100);
        bug.display();
        stroke(255);
        if(keycode == LEFT_ARROW)
            bug.move(-this.speed,0);
        if(keycode == RIGHT_ARROW)
            bug.move(this.speed,0);
        if(keycode == UP_ARROW)
            bug.move(0,-this.speed);
        if(keycode == DOWN_ARROW)
            bug.move(0,this.speed);
    }</code></p>

<pre><code>`function obj(){
    this.y=random(height);
    this.x=random(width);
    this.diameter=random(10,30);
    this.speed=10;
`

`this.move = function(posx,posy) {
        this.x+=posx;
        this.y+=posy;
  };
`

    `this.display = function(){
        ellipse(this.x,this.y,this.diameter,this.diameter);
    }
};
</code></pre>

<p>`</p>

<p>That's my code , but my object seems to be stuck in the canvas , not moving at all.</p>
]]></description>
   </item>
   <item>
      <title>Matter.js Collision Not Detecting</title>
      <link>https://forum.processing.org/two/discussion/21409/matter-js-collision-not-detecting</link>
      <pubDate>Wed, 15 Mar 2017 12:18:16 +0000</pubDate>
      <dc:creator>pyan83</dc:creator>
      <guid isPermaLink="false">21409@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to practice using matter.js to create top down levels Bomberman/Zelda style.</p>

<p>Right now I want to get my circle, which is controlled by arrow keys to move and bump into static squares but it is just going through them. Did I set it up incorrectly? I have been coding for three months, so I might be quite slow sorry!</p>

<pre><code>var Engine = Matter.Engine,
    World = Matter.World,
    Bodies = Matter.Bodies;

var engine = Engine.create();
var world = engine.world;

var player;
var rocks = [];
var cols = 7;
var rows = 7;

function setup() {
    createCanvas(750, 750);
    Engine.run(engine);

    player = new Player(300, 300, 25);

    var spacing = width / cols;
    for (var j = 0; j &lt; rows; j++) {
        for (var i = 0; i &lt; cols; i++) {
            var r = new Rocks(i * spacing, j * spacing);
            rocks.push(r);
        }
    }
}

function draw() {
    background(51);
    Engine.update(engine);
    for (var i = 0; i &lt; rocks.length; i++) {
        rocks[i].show();
    }
    player.show();
    player.move();
}

function Player(x, y, r) {
    this.body = Bodies.circle(x, y, r);
    this.r = r;
    World.add(world, this.body);

    this.show = function () {
        ellipse(x, y, this.r * 2);
    }

    this.move = function () {
        if (keyIsDown(RIGHT_ARROW))
            x += 10;
        if (keyIsDown(LEFT_ARROW))
            x -= 10;
        if (keyIsDown(UP_ARROW))
            y -= 10;
        if (keyIsDown(DOWN_ARROW))
            y += 10;
        x = constrain(x, this.r, height - this.r);
        y = constrain(y, this.r, width - this.r);
    }
}

function Rocks(x, y, w, h, options) {
    var options = {
        isStatic: true
    }
    this.body = Bodies.rectangle(x, y, h, w, options);
    this.w = w;
    this.h = h;
    this.size = player.r * 2;
    World.add(world, this.body);

    this.show = function () {
        rect(x, y, this.size, this.size);
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arrow keys Key_Pressed overpowering other keys?</title>
      <link>https://forum.processing.org/two/discussion/21208/arrow-keys-key-pressed-overpowering-other-keys</link>
      <pubDate>Mon, 06 Mar 2017 20:05:25 +0000</pubDate>
      <dc:creator>Polyrogue</dc:creator>
      <guid isPermaLink="false">21208@/two/discussions</guid>
      <description><![CDATA[<p>Hello there, so I have some fairly simple code here for a player spaceship:</p>

<pre><code>function keyPressed()
{
    if(key === " ")
    {
        bullets.push(new Bullet(player.x+((player.w)*player.dir),player.y+(player.h-3)));
    }
    if(keyCode == LEFT_ARROW)
    {
        moveLeft = true;
    }
    if(keyCode == RIGHT_ARROW)
    {
        moveRight = true;
    }
    if(keyCode == UP_ARROW)
    {
        moveUp = true;
    }
    if(keyCode == DOWN_ARROW)
    {
        moveDown = true;
    }
    return false;
}
</code></pre>

<p>And normally this works perfectly, except that if I hold down up+down, down+right, down+left, or up+left and pressing space does nothing and I am not sure why. Stranger still, holding down left+right or up+right still allows pressing space to work.</p>

<p>I'm not sure what's going on here. Any help would be greatly appreciated.</p>

<p>Thanks!</p>

<p>EDIT: I have an example right here: <a href="http://polyrogue.com/defender/index.html" target="_blank" rel="nofollow">http://polyrogue.com/defender/index.html</a></p>
]]></description>
   </item>
   <item>
      <title>keyIsDown _ button presses are not resolved</title>
      <link>https://forum.processing.org/two/discussion/19899/keyisdown-button-presses-are-not-resolved</link>
      <pubDate>Sat, 24 Dec 2016 13:26:16 +0000</pubDate>
      <dc:creator>strinda</dc:creator>
      <guid isPermaLink="false">19899@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>One of my friends wrote a small code - a car mooving through traffic - and has the following issue:
simultaneous key presses are not resolved individually at times, especially when playwers start mashing the buttons.</p>

<p>What is the right way of dealing with multiple keyboard presses?</p>

<p>This is the code:
<a href="https://www.openprocessing.org/sketch/396736" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/396736</a></p>
]]></description>
   </item>
   <item>
      <title>Question regarding KeyCode &amp; if/else statements</title>
      <link>https://forum.processing.org/two/discussion/19473/question-regarding-keycode-if-else-statements</link>
      <pubDate>Fri, 02 Dec 2016 17:11:56 +0000</pubDate>
      <dc:creator>George_Nan</dc:creator>
      <guid isPermaLink="false">19473@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am new to processing and currently I am only testing random staffs. I tried to create a simple circle which is moved by 50 to the UP and DOWN depending on which button on the keyboard you pressed. I am using a simple if/else method. The problem that occurred is the fact that for some reason when you press UP (for example) instead of moving just by 50 it keeps going upwards.</p>

<p>I tried to fix the problem by my own but my knowledge wasn't enough. If someone can help me and explain where my mistake is I will be really grateful.</p>

<p>The code that I wrote:</p>

<p>Main.js:</p>

<blockquote class="Quote">
  <p>var Circle; <br /><br /> function setup(){ <br /> &nbsp;&nbsp;&nbsp; createCanvas(600,600); <br /> &nbsp;&nbsp;&nbsp; Circle = new Circle(); <br /> } <br /><br /> function draw(){ <br /> &nbsp;&nbsp;&nbsp; background(65, 35, 255); <br /> &nbsp;&nbsp;&nbsp;  Circle.move(); <br /> &nbsp;&nbsp;&nbsp; Circle.show(); <br /> }</p>
</blockquote>

<p>Circle.js</p>

<blockquote class="Quote">
  <p>function Circle(){ <br /> &nbsp;&nbsp;&nbsp; this.x = 300; <br /> &nbsp;&nbsp;&nbsp; this.y = 300; <br /><br /> &nbsp;&nbsp;&nbsp; this.xup=50; <br /> &nbsp;&nbsp;&nbsp; this.yup = 50 ; <br /><br /> &nbsp;&nbsp;&nbsp; this.move = function(){ <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (keyCode === UP_ARROW){ <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.y = this.y - this.yup; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (keyCode === DOWN_ARROW){ <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.y = this.y + this.yup; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br /> &nbsp;&nbsp;&nbsp; } <br /><br /> &nbsp;&nbsp;&nbsp; this.show = function (){ <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fill(74, 124, 35); <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ellipse(this.x, this.y, 100, 100); <br /> &nbsp;&nbsp;&nbsp; } <br /> }</p>
</blockquote>
]]></description>
   </item>
   <item>
      <title>Erratic keyboard checking?</title>
      <link>https://forum.processing.org/two/discussion/19028/erratic-keyboard-checking</link>
      <pubDate>Mon, 14 Nov 2016 07:45:50 +0000</pubDate>
      <dc:creator>AndyD</dc:creator>
      <guid isPermaLink="false">19028@/two/discussions</guid>
      <description><![CDATA[<p>I am controlling a sprite with arrow keys and having it pick-up/put-down with the ENTER/RETURN key but find the response somewhat erratic. Sometimes key presses are missed and other times two strokes may register, even with a quick tap of the key.</p>

<p>So when the ENTER key is tapped, he might pick something up, not pick it up, or pick it up and put it straight back down.</p>

<p>Here's a snippet of the function call...</p>

<p><code>this.dir = checkKeys();</code></p>

<p>and here's the function...</p>

<pre><code>function checkKeys() {;

      if (keyIsDown(LEFT_ARROW)) {
        dir = "left";
      } else if (keyIsDown(RIGHT_ARROW)) {
        dir = "right";
      } else if (keyIsDown(UP_ARROW)) {
        dir = "up";
      } else if (keyIsDown(DOWN_ARROW)) {
        dir = "down";
      } else if (keyIsDown(13)) {
        mainSprite.pickUp();
      } else {
        dir = "standing";
      }
      return dir;
    }
</code></pre>

<p>this.dir is then passed through a switch to assign moves, actions, animations, etc...</p>

<p>Would I be better off using a built in function like keyPressed() rather than calling a function and looking for a pressed key? Either way, is there a way to always capture the first keypress in the buffer and to empty the buffer if needed 
(for when I want a "tap" but not a "hold")?</p>

<p>Hmm, I've just noticed I'm returning dir except when the ENTER key is pressed in which case I call another function within the object. Could this cause glitches? Maybe I should give dir a value here and call the function in the switch?</p>
]]></description>
   </item>
   <item>
      <title>p5.js in different browsers</title>
      <link>https://forum.processing.org/two/discussion/13502/p5-js-in-different-browsers</link>
      <pubDate>Fri, 13 Nov 2015 05:48:16 +0000</pubDate>
      <dc:creator>Andzejus</dc:creator>
      <guid isPermaLink="false">13502@/two/discussions</guid>
      <description><![CDATA[<p>Good day,</p>

<p>I'm not experienced with p5, processing or programming in general. So I was really excited when I saw, how easy it is to work with p5.</p>

<p>I made a silly little pong game. In p5 editor it works the way I want, just gets more and more slow after running for some time.</p>

<p>Then there is a possibility to run a sketch in browser (from p5 editor). The browser in my case is chrome. Sketch runs fine, even without slowing down. But as code got longer I noticed that it doesnt always run inside browser even if it works in editor. For example I had to put if statement inside another if statement instead of checking all conditions inside one if statement.</p>

<p>Another possibility is to run a sketch by launching index.html file. Here again I get different results. For example sounds do not want to get pre-loaded. I dont know, maybe it would get solved by properly hosting it somewhere instead running it like that. But this is not biggest issue (I just commented out all the sounds in the code). Even without sounds it gives different results in different browsers:</p>

<p>In windows I tried it on explorer, firefox, chrome and opera. It worked ok on all except firefox.</p>

<p>I also tried it on linux ubuntu, on chromium and firefox. Again, it didnt work on firefox. And on chromium it worked, but very slow.</p>

<p>So this is my story. And the question is: are there any guidelines, what should be avoided and what must be done, to make a code good for all browsers? Or maybe there is a possibility to export a sketch in some kind of exe file that could be sent to other people and I would be sure that it will run on their machines exactly the same as on mine?</p>
]]></description>
   </item>
   <item>
      <title>How to display a notification on the screen besides using the built in browser "alert()"</title>
      <link>https://forum.processing.org/two/discussion/12786/how-to-display-a-notification-on-the-screen-besides-using-the-built-in-browser-alert</link>
      <pubDate>Fri, 02 Oct 2015 21:30:05 +0000</pubDate>
      <dc:creator>jonl</dc:creator>
      <guid isPermaLink="false">12786@/two/discussions</guid>
      <description><![CDATA[<p>I want to be able to display a message like "Game Over" or "You win" to the user.</p>

<p>Ideally, I would just use a simple <code>alert("You Win!")</code>. However, because of <a rel="nofollow" href="https://github.com/processing/p5.js/issues/957#issuecomment-145114017">this bug</a>, I cannot do that.</p>

<p>What is the easiest, most "p5.js way" to be able to display a message like "Game Over" to the user that is not an <code>alert()</code> or <code>confirm()</code>, <code>prompt()</code> etc. ?</p>
]]></description>
   </item>
   </channel>
</rss>