struct CrystGLFW::MouseButton

Overview

A MouseButton represents a button on a mouse.

Defined in:

crystglfw/mouse_button.cr

Instance Method Summary

Instance Method Detail

def code : Int32 #

[View source]
def is?(*labels : Symbol) : Bool #

Returns true if the mouse button's label matches the given label. False otherwise.

window.on_mouse_button do |event|
  mouse_button = event.mouse_button
  if mouse_button.is? :mouse_button_left
    puts "the left mouse button was clicked."
  end
end

Also accepts multiple labels and returns true if the mouse button's label matches any of them.

window.on_mouse_button do |event|
  mouse_button = event.mouse_button
  if mouse_button.is? :mouse_buton_left, :mouse_button_middle, :mouse_button_right
    puts "The mouse button is standard."
  else
    puts "This must be one of those crazy mice with 100 buttons."
  end
end

This method accepts the following arguments:

  • *labels, any number of labels against which the mouse button will be checked.

[View source]