public KeyProcess RegisterKeys(ref KeyRegistrar keyRegistrar, RuleSet profile) { _keyHandlerState = new keyHandlerState() { current = null, previous = null }; _keyHandlerState.keyRegistrar = keyRegistrar; RuleValidation validation = new RuleValidation(typeof(keyHandlerState), null); RuleExecution execution = new RuleExecution(validation, _keyHandlerState); profile.Execute(execution); return(Start); }
public void Start(object sender, EventArgs e) { _ui.enabled = true; var role = _game.GetProfileName(_process, _items.CurrentId()); try { RuleSet ruleSet = null; XmlTextReader rulesReader = new XmlTextReader(role + ".rules"); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); ruleSet = (RuleSet)serializer.Deserialize(rulesReader); rulesReader.Close(); _hotKeyList = new KeyRegistrar(); var start = _keyHandler.RegisterKeys(ref _hotKeyList, ruleSet); try { _keyboardHook.Dispose(); } catch {; } _keyboardHook = new KeyboardHook(); _keyboardHook.KeyPressed += keyboardHook_KeyPressed; foreach (var hKey in _hotKeyList.keyList) { _keyboardHook.RegisterHotKey(hKey.modifier, hKey.key); } _threadQueue = new ConcurrentQueue <QueueMessage>(); if (_worker != null) { _worker.CancelAsync(); } _worker = new BackgroundWorker(); _worker.WorkerSupportsCancellation = true; _worker.WorkerReportsProgress = true; _worker.DoWork += (obj, eventArgs) => start(_threadQueue, _process, _items.CurrentId(), obj as BackgroundWorker, ruleSet); _worker.ProgressChanged += _worker_ProgressChanged; _worker.RunWorkerAsync(); } catch { var l = string.Format("Role {0} was not located", role); } }