jaywcjlove/hotkeys-js là một trong những repo tập trung giao diện mà TopGit theo dõi, hiện có 7.1k sao, viết chủ yếu bằng TypeScript. ➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~8kB) (gzipped: 3.8kB), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document demo preview, compatibility test. More examples.
import hotkeys from 'hotkeys-js';
hotkeys('f5', function(event, handler){
// Prevent the default refresh event under WINDOWS system
event.preventDefault()
alert('you pressed F5!')
});
Browser Usage
Or manually download and link hotkeys.js in your HTML. The library provides different formats for different use cases:
react-hotkeys is the React component that listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts. Detailed use method please see its documentation react-hotkeys.
react-hotkeys-hook - React hook for using keyboard shortcuts in components. Make sure that you have at least version 16.8 of react and react-dom installed, or otherwise hooks won't work for you.
Browser Support
Hotkeys.js has been tested and should work in.
Internet Explorer 6+
Safari
Firefox
Chrome
Supported Keys
HotKeys understands the following modifiers: ⇧, shift, option, ⌥, alt, ctrl, control, command, and ⌘.
The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete, f1 through f19, num_0 through num_9, num_multiply, num_add, num_enter, num_subtract, num_decimal, num_divide.
⌘ Command() ⌃ Control ⌥ Option(alt) ⇧ Shift ⇪ Caps Lock(Capital) fn Does not support fn ↩︎ return/Enter space
Defining Shortcuts
One global method is exposed, key which defines shortcuts when called directly.
hotkeys('*', function() {
if (hotkeys.shift) {
console.log('shift is pressed!');
}
if (hotkeys.ctrl) {
console.log('ctrl is pressed!');
}
if (hotkeys.alt) {
console.log('alt is pressed!');
}
if (hotkeys.option) {
console.log('option is pressed!');
}
if (hotkeys.control) {
console.log('control is pressed!');
}
if (hotkeys.cmd) {
console.log('cmd is pressed!');
}
if (hotkeys.command) {
console.log('command is pressed!');
}
});
setScope
Use the hotkeys.setScope method to set scope. There can only be one active scope besides 'all'. By default 'all' is always active.
// Define shortcuts with a scope
hotkeys('ctrl+o, ctrl+alt+enter', 'issues', function() {
console.log('do something');
});
hotkeys('o, enter', 'files', function() {
console.log('do something else');
});
// Set the scope (only 'all' and 'issues' shortcuts will be honored)
hotkeys.setScope('issues'); // default scope is 'all'
getScope
Use the hotkeys.getScope method to get scope.
hotkeys.getScope();
deleteScope
Use the hotkeys.deleteScope method to delete a scope. This will also remove all associated hotkeys with it.
hotkeys.deleteScope('issues');
You can use second argument, if need set new scope after deleting.
hotkeys.deleteScope('issues', 'newScopeName');
unbind
Similar to defining shortcuts, they can be unbound using hotkeys.unbind.
// unbind 'a' handler
hotkeys.unbind('a');
// Unbind a hotkeys only for a single scope
// If no scope is specified it defaults to the current
// scope (hotkeys.getScope())
hotkeys.unbind('o, enter', 'issues');
hotkeys.unbind('o, enter', 'files');
By default hotkeys are not enabled for INPUTSELECTTEXTAREA elements. Hotkeys.filter to return to the true shortcut keys set to play a role, false shortcut keys set up failure.
hotkeys.filter = function(event){
return true;
}
// How to add the filter to edit labels.
// <div contentEditable="true"></div>
// "contentEditable" Older browsers that do not support drops
hotkeys.filter = function(event) {
var target = event.target || event.srcElement;
var tagName = target.tagName;
return !(
target.isContentEditable ||
tagName == 'INPUT' ||
tagName == 'SELECT' ||
tagName == 'TEXTAREA'
);
}
hotkeys.filter = function(event){
var tagName = (event.target || event.srcElement).tagName;
hotkeys.setScope(
/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other'
);
return true;
}
noConflict
Relinquish HotKeys’s control of the hotkeys variable.
var k = hotkeys.noConflict();
k('a', function() {
console.log("do something")
});
hotkeys()
// -->Uncaught TypeError: hotkeys is not a function(anonymous function)
// @ VM2170:2InjectedScript._evaluateOn
// @ VM2165:883InjectedScript._evaluateAndWrap
// @ VM2165:816InjectedScript.evaluate @ VM2165:682
Development
To develop, Install dependencies, Get the code:
$ git https://github.com/jaywcjlove/hotkeys.git
$ cd hotkeys # Into the directory
$ npm install # or yarn install
To develop, run the self-reloading build:
$ npm run watch
Run Document Website Environment.
# Generate documentation website
$ npm run doc
# Live-generate documentation website
$ npm run start
To contribute, please fork Hotkeys.js, add your patch and tests for it (in the test/ folder) and submit a pull request.
$ npm run test
$ npm run test:watch # Development model
Contributors
As always, thanks to our amazing contributors!
Made with action-contributors.
Special thanks to @dimensi for the refactoring of version 4.0.
jaywcjlove/hotkeys-js thuộc nhóm Frontend trên TopGit, cùng 12 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về jaywcjlove/hotkeys-js ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/jaywcjlove/hotkeys-js là nguồn chính thức.
jaywcjlove/hotkeys-js có bao nhiêu sao?
jaywcjlove/hotkeys-js có 7.1k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/jaywcjlove/hotkeys-js. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
jaywcjlove/hotkeys-js có phải mã nguồn mở không?
Có — jaywcjlove/hotkeys-js phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/jaywcjlove/hotkeys-js.
jaywcjlove/hotkeys-js có trang demo không?
Dự án có trang chủ ở https://jaywcjlove.github.io/hotkeys-js. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
jaywcjlove/hotkeys-js là gì?
jaywcjlove/hotkeys-js (jaywcjlove/hotkeys-js) là dự án TypeScript trên GitHub. Theo mô tả gốc: ➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
jaywcjlove/hotkeys-js so với các dự án Frontend khác thế nào?
jaywcjlove/hotkeys-js được TopGit xếp vào nhóm Frontend, với 7.1k sao GitHub và viết bằng TypeScript. Xem trang chủ đề Frontend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về hotkeys-js?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về hotkeys-js.