Gemfile
your application's Gemfile
. gem 'mousetrap-rails'
$ bundle install
keybindings.js.coffee
and connect the library to Asset Pipeline by adding //= require mousetrap
to the js application manifest. $ rails generate mousetrap:install
data-keybinding
) out of the box to create page navigation. = link_to 'Homepage', root_path, data: { keybinding: 'h' }
allows you to go to the home page by clicking on the 'h'
Username
input field using the 'u'
button = text_field_tag 'Username', nil, data: { keybinding: 'u' }
// Mousetrap.bind '4', -> alert '4 pressed!' Mousetrap.bind 'x', (-> alert 'x pressed!'), 'keyup' // Mousetrap.bind 'command+shift+k', -> alert 'command+shift+k pressed!' false Mousetrap.bind ['command+k', 'ctrl+k'], -> alert 'command+k or ctrl+k pressed!' false // Mousetrap.bind 'g i', -> console.log 'gi sequence pressed!' Mousetrap.bind '* a', -> console.log '* a sequence pressed!' // - Mousetrap.bind 'up up down down left right left right ba enter', -> console.log 'You WIN!'
Source: https://habr.com/ru/post/152057/
All Articles