Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input Devices Library
#1
For QB64PE v4.4.0 and up.

Input Devices Library

Unified Joystick and Mouse Handling for QB64

The Input Devices Library provides a clean, reliable, and modernized interface for reading joystick and mouse input in QB64. It wraps QB64’s low‑level device functions into a consistent, high‑level API that delivers stable axis values, normalized directional data, button states, click and hold detection, scroll events, and window‑boundary awareness.

This library is ideal for games, editors, UI systems, and any interactive application that needs precise, real‑time device input.

FEATURES

JOYSTICK SUPPORT
• Automatic detection of joystick hardware
• Reads all axes and buttons from the controller
• Normalizes analog stick values
• Converts analog movement into digital X/Y direction (−1, 0, 1)
• Computes 0–360 degree angle for each stick
• Dead‑zone filtering to eliminate drift
• Supports left stick, right stick, and D‑pad
• Captures Z‑axis triggers and stick‑press buttons

MOUSE SUPPORT
• Full bit‑field mouse event reporting
• Detects button down, click, hold, and scroll wheel movement
• Tracks drag start and drag end coordinates
• Optional automatic _MouseInput clearing
• Works seamlessly inside real‑time loops

WINDOW BOUNDARY DETECTION
• Determines whether the mouse cursor is inside the program window
• Uses Windows API for accurate desktop‑level positioning
• Essential for UI hover logic, pausing input, and preventing off‑window clicks

INCLUDED COMMANDS

ReadJoyStick
Reads all joystick axes and buttons, updates the JoyStick() and Button() shared arrays, applies dead‑zone filtering, computes angles, and normalizes direction values.

MouseButtonStatus
Returns a bit‑field integer describing all mouse events:
1 left down
2 right down
4 middle down
8 left click
16 right click
32 middle click
64 left held
128 right held
256 middle held
512 scroll down
1024 scroll up

Also tracks drag start and end positions.

MBS
Convenience wrapper for MouseButtonStatus.
MBS(1) is identical to MouseButtonStatus(1).

MouseInApp
Returns TRUE if the mouse cursor is inside the program window.
Uses Windows API + GLUT offsets to convert desktop coordinates into app‑relative coordinates.

Axis_Type, JoyStick(), Button()
Internal structures and arrays storing joystick axis data, direction, angle, activity state, and button states.

WHY USE THIS LIBRARY?

QB64’s built‑in device functions are powerful but low‑level.
This library:

• Normalizes inconsistent axis values
• Removes joystick drift
• Converts analog movement into simple digital directions
• Distinguishes click vs. hold events
• Provides a unified bit‑field for mouse input
• Handles drag detection automatically
• Makes joystick and mouse input predictable and easy to use

Instead of wrestling with raw device data, you get clean, ready‑to‑use values ideal for gameplay logic, UI navigation, and interactive tools.

SUMMARY

The Input Devices Library gives QB64 developers a compact but powerful toolkit for real‑time joystick and mouse interaction. It abstracts away hardware quirks, normalizes input, and provides clean, intuitive data structures that make interactive programming dramatically easier.


Attached Files
.7z   Input Devices Library.7z (Size: 7.34 KB / Downloads: 9)
Reply
#2
Sounds awesome! But with that Windows API, is it cross-platform? Mac and Linux too<?>
Reply
#3
(02-01-2026, 10:23 PM)NakedApe Wrote: Sounds awesome! But with that Windows API, is it cross-platform? Mac and Linux too<?>

Only the MouseInApp function is windows only.  (And it's in a $IF Wrapper so it just excludes itself if you're not on a Windows system, so it still compiles. It only returns a value of 0 and never determines that you're inside a Windows Window, as... you're never really in a Windows' window. Big Grin )

The rest rely solely on QB64PE code.  Now if GLUT and _DeviceInput doesn't work (like I don't think it's ever really worked on your Mac properly), the other routines aren't going to work either.  

All I can suggest is give it a shot and see how it works for you.  It's only a few simple commands to try and test out, to see if it works on your system.  Wink
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Draw Library (for QB64PE v4.4 up) SMcNeill 5 784 02-12-2026, 01:54 AM
Last Post: madscijr
  KeyBoard Library (for QB64PE v 4.4.0 up) SMcNeill 3 607 02-01-2026, 09:40 PM
Last Post: SMcNeill
  Date Library (v 4.4.0 up) SMcNeill 4 246 02-01-2026, 09:37 PM
Last Post: SMcNeill
  Screen Library SMcNeill 0 573 05-09-2025, 02:41 PM
Last Post: SMcNeill
  Text to Speech Library (Windows only) SMcNeill 11 4,014 07-01-2023, 07:58 PM
Last Post: mnrvovrfc

Forum Jump:


Users browsing this thread: