Class: Browser::Event::Keyboard

Inherits:
UI show all
Defined in:
opal/browser/event/keyboard.rb

Defined Under Namespace

Classes: Definition

Constant Summary collapse

IE_MAP =

IE 11 at least has different names for those keys.

{
  'Down' => 'ArrowDown',
  'Up' => 'ArrowUp',
  'Left' => 'ArrowLeft',
  'Right' => 'ArrowRight',
  'Esc' => 'Escape',
  'Del' => 'Delete'
}

Instance Attribute Summary

Attributes inherited from Browser::Event

#callback, #on

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Browser::Event

aliases, #arguments, #arguments=, class_for, create, handlers, handles, #initialize, #name, name_for, new, #off, #prevent, #prevented?, #stop, #stop!, #stopped?, #target

Constructor Details

This class inherits a constructor from Browser::Event

Class Method Details

.construct(name, desc) ⇒ Object



51
52
53
# File 'opal/browser/event/keyboard.rb', line 51

def self.construct(name, desc)
  `new KeyboardEvent(#{name}, #{desc})`
end

.supported?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'opal/browser/event/keyboard.rb', line 8

def self.supported?
  Browser.supports? 'Event.Keyboard'
end

Instance Method Details

#charObject



111
112
113
# File 'opal/browser/event/keyboard.rb', line 111

def char
  `#@native.char || #@native.charCode || #{code ? code.chr : nil}`
end

#codeObject



107
108
109
# File 'opal/browser/event/keyboard.rb', line 107

def code
  `#@native.keyCode || #@native.which || nil`
end

#down?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'opal/browser/event/keyboard.rb', line 117

def down?
  name.downcase == 'keydown'
end

#keyObject Also known as: to_i



102
103
104
105
# File 'opal/browser/event/keyboard.rb', line 102

def key
  key = `#@native.key || #@native.keyIdentifier || nil`
  IE_MAP[key] || key
end

#press?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'opal/browser/event/keyboard.rb', line 121

def press?
  name.downcase == 'keypress'
end

#up?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'opal/browser/event/keyboard.rb', line 125

def up?
  name.downcase == 'keyup'
end