3.3: Events (mousePressed, keyPressed) – Processing Tutorial




About this tutorial:

Video duration: 00:07:22
This video demonstrates how the main animation loop can be interrupted by an “event”, such as a mouse press or key press.

Support this channel on Patreon:

Contact:

Send me your questions and coding challenges!:

Link to code on Github:

Processing:
Processing Foundation:
Learning Processing Book:

For More Processing…

Post Author: OfficeTutes.com

Apple lover, ICT and LEAN consultant, MS Office lecturer My other website with video tutorials - Tutorials, guides and news for iPhones and iPads

50 thoughts on “3.3: Events (mousePressed, keyPressed) – Processing Tutorial

    Phantom Ghost

    (May 23, 2020 - 12:30 am)

    Did i miss somthing keyPress not defined

    Silicon Slave

    (May 23, 2020 - 12:30 am)

    Thank you!

    Maria Chanivet Jacas

    (May 23, 2020 - 12:30 am)

    2020?

    Gizli Kalsın

    (May 23, 2020 - 12:30 am)

    please stop in somewhere but your videos are great

    Sullivan Lucier-Benson

    (May 23, 2020 - 12:30 am)

    I'm in an intro CS class and my group project partner is trying to use the mouseClicked function. Processing recognizes it but we're newbiez and we have no clue how to use it properly. How is the mouseClicked function used in processing?

    Ajb Videos

    (May 23, 2020 - 12:30 am)

    look at some of my robots

    Ajb Videos

    (May 23, 2020 - 12:30 am)

    great teaching, thanks

    QuackDMR

    (May 23, 2020 - 12:30 am)

    this is very difficult with what i'm trying to do. I'm trying to make a circle that follows the mouse. I used background and i tried to make it so it will add a rectangle where the mouse previously was. The background is overwriting the rectangle

    Abreu Boavida

    (May 23, 2020 - 12:30 am)

    Hi Dear Mr
    I am interested your channel so I want to ask you can explain source code c++ using hamming code encoder, noise and decoder and I want to setup in the arduino uno please share me source code and reply my question this.
    Thank you!

    Undefined

    (May 23, 2020 - 12:30 am)

    Well, that sounds like a perfect catch phrase for you "I'll think of that…"

    Mick Dingena

    (May 23, 2020 - 12:30 am)

    How can I make sure that a loop 'ends itself', for example when x crosses a certain value of x in fill(x,y,z) and if x > 255, – – > set x to 0 (without leaving it in the loop of x being zero??

    Giang Tu

    (May 23, 2020 - 12:30 am)

    Appreciate your work. Your energy and enthusiasm. Just want you to know that you have changed someone’s life.

    team doodz

    (May 23, 2020 - 12:30 am)

    how do i wait until it has then been released?

    KronosUber

    (May 23, 2020 - 12:30 am)

    In an introductory Computer science class and we're starting out with processing. The class moves too slow for me when teaching code. Glad I have you around to teach me at my own pace!

    Mike_Vahe Moubayed

    (May 23, 2020 - 12:30 am)

    Void setup() {

    Background(50);
    }

    Void draw(){
    Print("best channel ever");
    }

    Cosmic Famicommunist

    (May 23, 2020 - 12:30 am)

    Thanks for these tutorials! I started a blog that will keep track of my progress of me learning in here and through my Valencia coding course 🙂

    https://fractalcoding.blogspot.com/2019/06/this-code-will-generate-epileptic.html

    That's what I've learned so far through your videos! As the URL suggests it DOES contain epileptic imagery so please be mindful when watching! Do you have any suggestions as to how I could improve this code? Maybe condense some of the many point and rectangle commands?

    Wolfalpha

    (May 23, 2020 - 12:30 am)

    Hey can someone tell me the command where upon collision with another object you lose the game ?

    eboy-predator Markiplier

    (May 23, 2020 - 12:30 am)

    I HAVE THE POWEEEERR!!

    Daniella Collison

    (May 23, 2020 - 12:30 am)

    LEEEGGGEEENNND
    I thought id really hate coding but you've taught me in such an entertaining and fun way of learning! Once again, you've taught me better than approximately 4 demonstrators at my university.

    Brendan Hughes

    (May 23, 2020 - 12:30 am)

    if that is a tutorial on what happens when the mouse is pressed, what when it is not being pressed and using the code 'else'……

    Eira Bleddyn

    (May 23, 2020 - 12:30 am)

    You're really animated, and you explained this really clearly. Thank you so much! I'm a student and was really struggling with this stuff. So thank you!

    Mipsee

    (May 23, 2020 - 12:30 am)

    What if I want something to happen if the same key is pressed twice?

    Tahsin Sayed Chowdhury

    (May 23, 2020 - 12:30 am)

    Which programming language is this??

    Drin Ramadani

    (May 23, 2020 - 12:30 am)

    looking your vids in 2019 this was low quality

    MrKA1961

    (May 23, 2020 - 12:30 am)

    But what about custom event functions???! Anyone can help me pls.

    Gibe Mass

    (May 23, 2020 - 12:30 am)

    1.5 speed is a treat.

    Noah

    (May 23, 2020 - 12:30 am)

    Thanks for this Video, at the moment i am programming my first Java MiniGame and I didn't know how to use the mouseclick. I searched my problem in YouTube, found your Video. I was instandly happy of working of my game so well 🙂

    Gabe Mott

    (May 23, 2020 - 12:30 am)

    Perhaps I am wrong, here is the NEXT video suggested by YouTube "4.1" https://www.youtube.com/watch?v=B-ycSR3ntik is that right?

    Tomato

    (May 23, 2020 - 12:30 am)

    I love your gestures <3

    CrouchingPython

    (May 23, 2020 - 12:30 am)

    Love these tutes!

    Bob Irving

    (May 23, 2020 - 12:30 am)

    Best tutes ever!

    Tyrese Love

    (May 23, 2020 - 12:30 am)

    can you make a video that goes more into KeyPressed other then color change ! I have assignments and your videos help allot. Im having issues with using ASCII keys( TAB, ESC , DELETE, RETURN) for movements and having problems with limited directions or examples.

    18bovende

    (May 23, 2020 - 12:30 am)

    I'M GOING CRAZZZZZYYYYYY!!!

    void setup() {
    size(640, 360);
    background(50);
    }

    void draw() {

    fill(150);
    stroke(255);
    rectMode(CENTER);
    rect(width-mouseX, height-mouseY, 100, 50);

    line(mouseX, 20, mouseY, 80);

    line(mouseX, mouseY,pmouseX,pmouseY);
    }

    void mousePressed(){
    background(50);
    }

    Kirsten Kennedy

    (May 23, 2020 - 12:30 am)

    I wish this guy was my CS prof

    Alice Witland

    (May 23, 2020 - 12:30 am)

    How do you make music play when you click in a certain area?

    Kresten Sckerl

    (May 23, 2020 - 12:30 am)

    Is it just at me the video is lag-ish, like low frame-rate?

    Dov Mashleh

    (May 23, 2020 - 12:30 am)

    I really appreciate your contribution to popularization and clarification of processing language, looks like many people like your style.. yep, it's very energized and could share such mood, but i personaly can't stand it for long: extremaly intensive and a bit sponteneous movement in front of static code on background distracts a lot. Anyway, you are doing it great, but i'm sure it could be even better (and popular as result) if you will try to moderate your gesturing and stick to not-whole-arm and, preferably, standart"" general gestures-illustrators. Also can be adviced to take a close look on, as example of bearded vlog-lecturer, Vsauce's (M Stevens) movement in frame.

    Elijah Hassan

    (May 23, 2020 - 12:30 am)

    I want make an event happen when a specific key is pressed

    Ellena Mori

    (May 23, 2020 - 12:30 am)

    I have question about GUI of Java. Movement of a ball. The path points are already given. Just move the ball through this given points.I have no clue how to implement it. Can I get your mail id so that I can mail my code.

    sasukeuchiha998

    (May 23, 2020 - 12:30 am)

    A bit of a question. If you are using mousePressed and keyPressed as built in variables, how do you denote a value or specific key to it?
    Do you set it up as void keyPressed() where keyCode=LEFT/RIGHT/UP/DOWN and the like?

    Nirary Ishaia

    (May 23, 2020 - 12:30 am)

    You make my life easier mate!

    Nova

    (May 23, 2020 - 12:30 am)

    frameRate(4)

    Ball King

    (May 23, 2020 - 12:30 am)

    How do you make it so that something occurs when the mouse is pressed in a certain location

    Anirudh Bhardwaj

    (May 23, 2020 - 12:30 am)

    hey, I want to create a painting program for fun and want it to draw when you are holding the mouse. Please help. Thanks.

    TechJockeyHD

    (May 23, 2020 - 12:30 am)

    Making coding look fun #dreamComeTrue

    I'm a Koala

    (May 23, 2020 - 12:30 am)

    draws a line whenever the mouse is pressed, press a key to reset the background(thus resetting the canvas so you can make another ugly drawing).

    void setup() {
    size(500, 500);
    background(50);
    }

    void draw() {
    if (mousePressed == true) {
    stroke(0, 255, 0);
    line(pmouseX, pmouseY, mouseX, mouseY);
    }
    }

    void keyPressed() {
    background(50);
    }

    Cody Bishop

    (May 23, 2020 - 12:30 am)

    Is setup a prebuilt func

    Kelsey Mosley

    (May 23, 2020 - 12:30 am)

    can you use the mousePress multiple times to change a color on the same object?

    Jan Willem

    (May 23, 2020 - 12:30 am)

    Is it the shader that makes the lighting so weird in this example? I can't seem to get softly illuminated polygons

Leave a Reply

Your email address will not be published. Required fields are marked *