Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve hotkey issues #4

Open
zero-plusplus opened this issue Sep 5, 2021 · 0 comments
Open

Solve hotkey issues #4

zero-plusplus opened this issue Sep 5, 2021 · 0 comments
Labels
draft Draft of new features

Comments

@zero-plusplus
Copy link
Owner

zero-plusplus commented Sep 5, 2021

The hotkey syntax is convenient, but has the disadvantage that it is difficult to do programmable operations such as turning off specific hotkeys.

This can be solved by creating a class that abstracts the hotkey.
This would also allow us to set up hotkeys using external files such as json files, for example.

However, there are still some inconveniences.
Since I am using hotkeys to change the keyboard layout, I may want to temporarily turn off those hotkeys when playing a single player game.
So I will solve this problem by grouping those hotkeys and providing a way to control them all at once.

The next thing to think about is the actions of the hotkeys.
In most cases, the Send function and user-defined functions are sufficient, but it would be useful to be able to assign more related actions with a single hotkey definition.

The following three advanced actions are the ones I have actually implemented and found useful.

  1. In addition to the defined hotkeys, the action can be switched by pressing modifier keys (Shift, Ctrl, etc.) at the same time. This is useful if you are using combination keys such as a & b.
  2. Switch actions based on how many times a non-modifier key of a defined hotkey is pressed within a specified time.
  3. Switch between actions by additionally keying after the defined hotkey. Optionally, a tooltip can be used to indicate which key press will trigger which action or not.
  4. Searchable and selectable actions, similar to VSCode's command palette. For example, you can open a specific project by VSCode from a list of projects. The interface can be implemented with tooltips or Gui

These were enough to solve my frustration, but may not be enough to solve the frustration of others.

If you have any ideas, please comment.


bee.Hotkey's interface

class Hotkey {
  __New(key, action, condition:= "")
  register()
  on()
  off()
  toggle()
}

bee.HotkeyGroup's interface

class HotkeyGroup {
  __New(defaultCondition := "")
  add(hotkey)
  add(key, action := "")
  add(condition, key, action := "")
  add(keys, action := "")
  add(condition, keys, action := "")
  add(keyMap)
  add(condition, keyMap)
  register()
  on()
  off()
  toggle()
}

Example of use.

; 2.0-beta.1
hotkeys := bee.HotkeyGroup()

; Add hotkey
hotkeys.add(bee.Hotkey("+!a", "{Shift Down}abc{Shift Up}"))
; hotkeys.add("+!a", "{Shift Down}abc{Shift Up}") ; shorthund
hotkeys.add("+!b", () => Something())

; Assign the same action
hotkeys.add([ "+!c", "+!d" ], () => Something())

; Defining hotkeys using objects and maps
hotkeys.add({
  %"+!e"%: () => Something()
})
hotkeys.add(Map(
  "+!e", () => Something()
))

; If you omit the second argument, you can define a hotkey that does nothing. This is useful for disabling unwanted shortcut keys in Windows.
hotkeys.add([ "+!e", "+!f"])

; Register all hotkeys. The HotkeyGroup will not do anything until this is called.
hotkeys.register()
@zero-plusplus zero-plusplus added the draft Draft of new features label Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft Draft of new features
Projects
None yet
Development

No branches or pull requests

1 participant