Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Krombik committed Oct 1, 2022
1 parent a14a99f commit 96d27da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,29 +793,32 @@ Registers a hotkey, if any hotkey is already registered for this **key**, [unreg
```ts
import { GlobalHotkey } from "keysender";

new GlobalHotkey({ // logs "hi" after pressing "num+"
new GlobalHotkey({
// logs "hi" after pressing "num+"
key: "num+",
mode: "once",
action() {
console.log("hi");
}
},
});

new GlobalHotkey({ // logs "hi" every 50 milliseconds while "num*" is pressed
new GlobalHotkey({
// logs "hi" every 50 milliseconds while "num*" is pressed
key: "num*",
mode: "hold",
action() {
console.log("hi");

return true;
},
delay: 50
delay: 50,
});

let i = 0;

new GlobalHotkey({ // logs "hi" every 50 milliseconds after "num/" is pressed
key: "num/", // until "num/" be pressed again or i become > 50
new GlobalHotkey({
// logs "hi" every 50 milliseconds after "num/" is pressed
key: "num/", // until "num/" be pressed again or i become > 50
mode: "toggle",
action() {
i++;
Expand All @@ -830,23 +833,27 @@ new GlobalHotkey({ // logs "hi" every 50 milliseconds after "num/" is pressed
},
});

new GlobalHotkey({ // after "a" is pressed if i <= 50 - logs "hi" every 50 milliseconds
key: "a", // until "a" be pressed again
let j = 0;

new GlobalHotkey({
// after "a" is pressed if i <= 50 - logs "hi" every 50 milliseconds
key: "a", // until "a" be pressed again
mode: "toggle",
isEnabled() {
return i <= 50;
}
isEnable() {
return j <= 50;
},
action() {
i++;
j++;

console.log("hi");
console.log(j);

return true;
},
delay: 50
delay: 50,
});

new GlobalHotkey({ // logs "hi" every 50 milliseconds while "num-" is pressed,
new GlobalHotkey({
// logs "hi" every 50 milliseconds while "num-" is pressed,
key: "num-", // logs Release.BY_KEYBOARD when "num-" is released
mode: "hold",
action() {
Expand All @@ -856,7 +863,7 @@ new GlobalHotkey({ // logs "hi" every 50 milliseconds while "num-" is pressed,
},
after(reason) {
console.log(reason);
}
},
});
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"source": "src/index.ts",
"main": "./dist/index.js",
"scripts": {
"install": "node-gyp rebuild",
"build": "yarn tsc"
},
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit 96d27da

Please sign in to comment.