From 16c8042c265ee1e691d814f33fd588af61e80739 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Tue, 20 Aug 2024 20:05:55 -0400 Subject: [PATCH] add convienence methods for type of button --- input.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/input.go b/input.go index 1f0cff6..a4e69cc 100644 --- a/input.go +++ b/input.go @@ -36,6 +36,16 @@ func (b Button) String() string { return name } +// IsMouseButton returns true if the button is one of the mouse buttons. +func (b Button) IsMouseButton() bool { + return b >= mouseButtonStart && b <= mouseButtonEnd +} + +// IsKeyboardButton returns true if the button is one of the keyboard buttons. +func (b Button) IsKeyboardButton() bool { + return b >= keyButtonStart && b <= keyButtonEnd +} + const UnknownButton Button = -1 const ( // List of all mouse buttons. @@ -173,6 +183,12 @@ const ( // Last iota NumButtons int = iota + // Internal mappings bookending keyboard and mouse buttons. + mouseButtonStart = MouseButton1 + mouseButtonEnd = MouseButton8 + keyButtonStart = KeySpace + keyButtonEnd = KeyMenu + // Aliases MouseButtonLeft = MouseButton1 MouseButtonRight = MouseButton2