KeyboardEvent
using AngleSharp.Attributes;
using AngleSharp.Extensions;
using System.Collections.Generic;
namespace AngleSharp.Dom.Events
{
[DomName("KeyboardEvent")]
public class KeyboardEvent : UiEvent
{
private string _modifiers;
[DomName("key")]
public string Key { get; set; }
[DomName("location")]
public KeyboardLocation Location { get; set; }
[DomName("ctrlKey")]
public bool IsCtrlPressed {
get {
return _modifiers.IsCtrlPressed();
}
}
[DomName("shiftKey")]
public bool IsShiftPressed {
get {
return _modifiers.IsShiftPressed();
}
}
[DomName("altKey")]
public bool IsAltPressed {
get {
return _modifiers.IsAltPressed();
}
}
[DomName("metaKey")]
public bool IsMetaPressed {
get {
return _modifiers.IsMetaPressed();
}
}
[DomName("repeat")]
public bool IsRepeated { get; set; }
[DomName("locale")]
public string Locale {
get {
if (!base.IsTrusted)
return null;
return string.Empty;
}
}
public KeyboardEvent()
{
}
public KeyboardEvent(string type, bool bubbles, bool cancelable, IWindow view, int detail, string key, KeyboardLocation location, string modifiersList, bool repeat)
{
Init(type, bubbles, cancelable, view, detail, key, location, modifiersList, repeat);
}
[DomConstructor]
public KeyboardEvent(string type, IDictionary<string, object> eventInitDict = null)
: base(type, eventInitDict)
{
Key = (eventInitDict.TryGet("key") ?? string.Empty).ToString();
Location = (KeyboardLocation)(eventInitDict.TryGet<int>("location") ?? 0);
IsRepeated = (eventInitDict.TryGet<bool>("repeat") ?? false);
_modifiers = (eventInitDict.TryGet("code") ?? string.Empty).ToString();
}
[DomName("getModifierState")]
public bool GetModifierState(string key)
{
return _modifiers.ContainsKey(key);
}
[DomName("initKeyboardEvent")]
public void Init(string type, bool bubbles, bool cancelable, IWindow view, int detail, string key, KeyboardLocation location, string modifiersList, bool repeat)
{
Init(type, bubbles, cancelable, view, detail);
Key = key;
Location = location;
IsRepeated = repeat;
_modifiers = modifiersList;
}
}
}