https://github.com/tricked-dev/coolkeybinds
https://github.com/tricked-dev/coolkeybinds
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tricked-dev/coolkeybinds
- Owner: Tricked-dev
- License: unlicense
- Created: 2023-10-08T08:53:14.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-08T08:55:08.000Z (over 2 years ago)
- Last Synced: 2025-03-05T23:44:41.714Z (about 1 year ago)
- Language: TypeScript
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Coolkeybinds
Keybinds as json
You can use this library unde the [`The Unlicense`](./LICENSE) license. the code for coolkeybinds can be found in [./src/lib/coolkeybinds.ts](./src/lib/coolkeybinds.ts) and [./src/lib/keybinds.ts](./src/lib/keybinds.ts) just copy the typescript files over to your repo and import them and your done!
If you have any improvements / performance improvements to suggest you can create a pull request
List of the key names
```js
import { CoolKeyBinds, type KeyBindOption } from "./coolkeybinds";
const keybindsList: KeyBindOption[] = [
{
name: "reload",
bind: "ctrl+r",
},
{
name: "add",
bind: ["=", "ctrl+a"],
when: "menu"
},
{
name: "sub",
bind: ["-", "ctrl+s"],
when: "menu"
},
{
name: "reset",
bind: ["ctrl+z"]
},
{
name: "left",
bind: "ArrowLeft",
when: "magic"
},
{
name: "right",
bind: "ArrowRight",
when: "magic"
},
{
name: "up",
bind: "ArrowUp",
when: "magic"
},
{
name: "down",
bind: "ArrowDown",
when: "magic"
},
{
name: "magic",
bind: ["ctrl+m"],
}
]
const functions = {
"reload": () => window.location.reload(),
"magic": () => state.magic = !state.magic
}
export function findAncestorFocus(elementsObj: Record) {
const result = {} as Record;
for (let key in elementsObj) {
result[key] = false;
}
let focused = document.activeElement;
while (focused) {
for (let key in elementsObj) {
if (focused === elementsObj[key]) {
result[key] = true;
}
}
focused = focused.parentElement;
}
return result;
}
export const state: Record = {
magic: false
}
const varFunction = () => {
return {
...state,
...findAncestorFocus({
"menu": document.getElementById("form")!
})
}
}
const keybinds = new CoolKeyBinds(varFunction, functions);
// this overwrites previous set keybinds
keybinds.setKeybinds(keybindsList);
export default keybinds
```