Skip to content

Commit

Permalink
add convienence methods for type of button
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Ray committed Aug 21, 2024
1 parent dda5970 commit 16c8042
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16c8042

Please sign in to comment.