Hotkey#
import Yasb
A global keyboard shortcut for your widget. While YASB is running, pressing the keys anywhere in Windows triggers
onActivated.
Guide: Writing widgets
Example#
A Hotkey works inside a widget that a bar loads. This widget shows a toast on Alt+Shift+H:
// %USERPROFILE%\.config\yasb\widgets\HelloKey\HelloKey.qml
import QtQuick
import Yasb
import Yasb.Bar
Item {
// Set by YASB to the bar the widget is in
required property BarBase bar
Hotkey {
keys: "alt+shift+h"
onActivated: Notifier.toast("HelloKey", "Hello from the keyboard")
}
}
Put it on a bar in config.yaml:
bars:
yasb-bar:
widgets:
right:
- HelloKey
Built-in widgets that support a shortcut have a hotkey option. It's empty by default, except Launchpad's, which is
alt+l. Some have more, like OBS's recordHotkey. To set one, run yasbc addons install Cpu to get the widget's
options, then set hotkey in %USERPROFILE%\.config\yasb\widgets\Cpu\Cpu.qml and save. See
Widgets.
Which bar gets it#
If you have a bar on each screen, each bar has its own copy of your widget. Only the copies on the screen chosen by
screen receive the key press. Holding the keys down triggers it once.
YASB reads shortcuts when the bars load, and again when saving a file rebuilds a bar. If keys changes while the widget
is running, the change takes effect at that point.
Hotkey#
Properties#
keys : string#
The shortcut: modifiers and one key joined by +, in any case, such as alt+shift+c or win+f1. "" for none.
- Modifiers:
win(orwindows,super,meta),alt,ctrl(orcontrol) andshift. - Keys: a letter or digit,
f1tof24,space,tab,enter(orreturn),esc(orescape),backspace,delete(ordel),insert(orins),home,end,pageup(orpgup),pagedown(orpgdn),left,up,right,down,pause,capslock(orcaps),numlock,scrolllock,printscreen(orprtsc),numpad0tonumpad9,multiply,add,subtract,decimal,divide,semicolon,equal(orequals),comma,minus,period,slash,backquote(orgrave),bracketleft,backslash,bracketrightandquote.
A shortcut isn't registered if it has an unknown key or more than one key, or if another app already uses it. Each case logs a warning.
Default: ""
screen : string#
Which bar's widget gets the press: active (the screen of the foreground window), cursor (the screen under the mouse)
or primary (the primary screen). When several widgets use the same keys, the screen of the first one YASB finds
applies to all of them.
Default: "active"
Signals#
activated()#
Emitted when the keys are pressed. If several widgets on that bar use the same keys, all of them receive it.