Class KeybindAttribute
Specifies that a method should be invoked when a specific hotkey is pressed.
Inherited Members
Namespace: EyeAuras.Scripting.Api
Assembly: EyeAuras.Scripting.dll
Syntax
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public sealed class KeybindAttribute : Attribute
Remarks
This attribute is designed to simplify hotkey handling in scripts by allowing developers to decorate methods with hotkey definitions. Each decorated method will be automatically registered as a hotkey action when the script is initialized.
Supported hotkeys can include:
- Single keys (e.g., "A", "F5", "Esc").
- Key combinations with modifiers (e.g., "Ctrl+Shift+P", "Alt+Enter").
- Special keys like "VolumeUp", "MediaPlayPause", etc.
**Suppression Behavior:** By default, the associated hotkey event is suppressed, meaning the key's default behavior (e.g., opening the Start menu for the Windows key) will be blocked. You can change this by setting SuppressKey to `false`.
**Modifier Handling:** By default, the attribute ignores modifier keys unless explicitly included in the `Hotkey` string. If IgnoreModifiers is set to `true`, the hotkey will trigger regardless of any active modifiers.
**Multiple Attributes:** You can apply multiple `RunOnKeyPressAttribute` attributes to the same method, allowing the method to respond to different hotkeys.
public class MyScript
{
[RunOnKeyPress("Ctrl+Shift+P")]
public void OpenPanel()
{
Console.WriteLine("Opening panel...");
}
[RunOnKeyPress("F1", SuppressKey = false)]
public void ShowHelp()
{
Console.WriteLine("Displaying help...");
}
[RunOnKeyPress("T", IgnoreModifiers = true)]
public void DebugTrace()
{
Console.WriteLine("Debug trace active.");
}
}
**Important Notes:** - Hotkey definitions are case-insensitive. - Invalid or unsupported hotkeys will result in runtime exceptions during registration. - Ensure that conflicting hotkeys are avoided to prevent unexpected behavior.
Constructors
Name | Description |
---|---|
KeybindAttribute() | |
KeybindAttribute(string) |
Properties
Name | Description |
---|---|
ActivationType | Specifies when the keybind should trigger: on key press (KeyDown), on key release (KeyUp), or both. |
Hotkey | The hotkey gesture that activates this trigger. |
IgnoreModifiers | Specifies whether modifier keys (Ctrl, Alt, Shift) are ignored in the hotkey trigger. |
SuppressKey | Determines whether the hotkey event is suppressed after being triggered. |
Methods
Name | Description |
---|---|
Equals(object) | |
GetHashCode() | |
ToString() |