So far in KitLab, we’ve seen how to create windows, add views, draw text, and respond to button clicks.
Now it’s time to go deeper into direct user input: handling mouse and keyboard events inside a BView.
In Haiku, every BView can capture events such as clicks, key presses, and mouse movement. By overriding the appropriate methods, you can make your application interactive in a very natural way.
The most common input hooks you can override are:
MouseDown(BPoint point) – called when the user clicks inside the view.
MouseUp(BPoint point) – called when the mouse button is released.
MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage) – called when the mouse moves across the view.
KeyDown(const char* bytes, int32 numBytes) – called when a key is pressed while the view has focus.
KeyUp(const char* bytes, int32 numBytes) – called when a key is released.
The following program combines mouse and keyboard input.
Left-click inside the window: the circle moves to that position.
Press the C key: the circle changes color randomly.
MouseDown moves the circle to the click location and requests focus.
KeyDown checks if the key pressed is "C" and updates the circle’s color randomly.
Invalidate() tells Haiku to call Draw() again, refreshing the view with the updated state.
Because we call MakeFocus(true), our view correctly receives keyboard input after a mouse click. Don't forget to add this line to handle events in your view!
Then launch the program:
./InputApp
You’ll see a window with a circle in the middle.

Click anywhere, and the circle follows:

Press C, and the circle changes its color randomly:

Press again C, and the circle changes its color one more time:

Nice isn't it ?
Handling input is the cornerstone of interactive applications.
With just two overridden methods, we’ve created an app that responds to both mouse and keyboard.
This foundation enables:
Games and interactive art
Drawing tools or editors
Custom widgets with keyboard shortcuts
Now that we can capture input events, the next KitLab entries will explore:
Stay tune in the coming weeks :)