Skip to content

Add input support; extract glfw crate.#95

Open
tychedelia wants to merge 6 commits intoprocessing:mainfrom
tychedelia:input
Open

Add input support; extract glfw crate.#95
tychedelia wants to merge 6 commits intoprocessing:mainfrom
tychedelia:input

Conversation

@tychedelia
Copy link
Member

Fixes #41

Adds two new crates:

  • processing_input, which handles extracting input data from Bevy when requested.
  • processing_glfw, which is now just a common crate for GLFW related stuff, rather than having it separately versioned in examples and pyo3.

The goal here is to use Bevy's input machinery, rather than directly going from GLFW to processing. As such, when we poll events from GLFW, we feed them into Bevy as regular Bevy input events. We "flush" input by running the PreUpdate schedule which allows Bevy's internal input bookeeping to populate the respective ButtonInput, etc., resources.

One thing to note is that processing is kind of weird in that many input states are not reset every frame. So if you check for a pressed key it will remain "pressed" until a new key is pressed. For example, see the docs here: https://p5js.org/reference/p5/keyPressed/. As such, we need to track the most recent key press separately.

Something else worth noting is the strategy for allowing users to reference stuff like mouse_x in their Python sketches, where mouse_x is magically updated every frame. To do so, we set those as global variables in the scope of the draw function. This strategy likely has some gaps, and may need to be expanded on later.

@tychedelia tychedelia requested a review from catilac March 24, 2026 20:10
@catilac
Copy link
Contributor

catilac commented Mar 25, 2026

So many match statements 🌀 🌀
I haven't tested this yet, but it looks good! I'll test and merge later today.

Questions:

  • What does this mean for Processing4? I think P4 can leave it's input as is, but we also have the option of using the libprocessing input work. I assume it will be a similar story for p5.js if they wanted to use bits of the wasm
  • Additionally, I'm curious about how this will connect to picking. In my mind it seems like a straight forward path, of taking a mouse coordinate and sending it over to bevy. Is that an over simplification?

Excitement:
This is going to be so fun for the audio work i'm doing

@tychedelia
Copy link
Member Author

What does this mean for Processing4?

For Processing4, we also use GLFW, so they'll just call our input APIs to forward those input events from GLFW Java to Bevy.

Additionally, I'm curious about how this will connect to picking

Yes! It should be trivial to enable picking now. I'll just have to do some research into prior art here in the processing world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User Input API

2 participants