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)


11
12
13
14
15
16
17
# File 'lib/cura/event/key_down.rb', line 11

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)


29
30
31
# File 'lib/cura/event/key_down.rb', line 29

def name
  @name
end

Instance Method Details

#characternil, String

Get the printable character for the key.

Returns:

  • (nil, String)


43
44
45
# File 'lib/cura/event/key_down.rb', line 43

def character
  Key.character_from_name(@name)
end

#control?Boolean

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

Returns:

  • (Boolean)


22
23
24
# File 'lib/cura/event/key_down.rb', line 22

def control?
  @control
end

#printable?Boolean

Get whether the key is printable.

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/cura/event/key_down.rb', line 34

def printable?
  return false if @control
  
  Key.name_is_printable?(@name)
end