Class: Cura::Event::KeyDown

Inherits:
Base
  • Object
show all
Defined in:
lib/cura/event/key_down.rb

Overview

Dispatched when a key’s state changes from up to down.

Instance Attribute Summary collapse

Attributes inherited from Base

#created_at, #target

Instance Method Summary collapse

Methods inherited from Base

#==, #dispatch, inherited, name, #to_h

Methods included from Attributes::HasAttributes

included, #update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ KeyDown

Returns a new instance of KeyDown.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/cura/event/key_down.rb', line 7

def initialize(attributes={})
  @control = false

  super

  raise ArgumentError, "name must be set" if @name.nil?
end

Instance Attribute Details

#nameInteger

Get the key name.

Returns:

  • (Integer)


25
26
27
# File 'lib/cura/event/key_down.rb', line 25

def name
  @name
end

Instance Method Details

#characternil, String

Get the printable character for the key.

Returns:

  • (nil, String)


39
40
41
# File 'lib/cura/event/key_down.rb', line 39

def character
  Key.character_from_name(@name)
end

#control?Boolean

Get whether the key was pressed while holding the control key.

Returns:

  • (Boolean)


18
19
20
# File 'lib/cura/event/key_down.rb', line 18

def control?
  @control
end

#printable?Boolean

Get whether the key is printable.

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/cura/event/key_down.rb', line 30

def printable?
  return false if @control

  Key.name_is_printable?(@name)
end