/* Loads user defined macros to the collection */ private void loadUserDefinedCollection() { KeyMacro km; if (File.Exists(macroFolderPath)) { using (StreamReader reader = new StreamReader(macroFolderPath)) { while (!reader.EndOfStream) { var readLine = reader.ReadLine(); var tokens = readLine.Split(','); if (tokens.Length > 1) { var macroString = tokens[1].Split('\\'); keyNames.Add(tokens[0]); km = new KeyMacro { macroName = tokens[0], macroString = macroString.ToList() }; MacroKeyBinds.Add(km); } } } } return; }
private void AddMacro(KeyMacro macro) { ListViewItem item = new ListViewItem(); item.Text = macro.Name; item.SubItems.Add(macro.GetRecordString()); item.Tag = macro; lstMacros.Items.Add(item); }
private void btnRecAdd_Click(object sender, EventArgs e) { var records = lstMacroKeys.Items.Cast <ListViewItem>().Reverse().Select(x => (KeyMacroRecord)x.Tag).ToArray(); var macro = new KeyMacro(cfgMacroName.Text, records); Program.Macros.Add(macro); AddMacro(macro); RecordingDone = false; }
private void validateOnHoldMacro(KeyMacro macroSelected) { foreach (var modkey in model.validHoldMacro) { if (modkey.macroString[1].Equals(macroSelected.macroString[1])) { return; } } throw new Exception("Invalid on hold macro must start with a modifier key."); }
/* Loads the valid on hold macro list to be checked when a user tries to set an on hold macro. */ private void loadValidOnHoldMacros() { var resourceName = "GuiShellTest.Resources.supportedOnHoldMacroModifiers.csv"; KeyMacro km; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var readLine = reader.ReadLine(); var tokens = readLine.Split(','); var macroString = tokens[1].Split('\\'); keyNames.Add(tokens[0]); km = new KeyMacro { macroName = tokens[0], macroString = macroString.ToList() }; validHoldMacro.Add(km); } } }
/* Loads predefined macro list collection */ private void loadPredefinedMacroCollection() { var resourceName = "GuiShellTest.Resources.defaultKeyMacros.csv"; KeyMacro km; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var readLine = reader.ReadLine(); var tokens = readLine.Split(','); var macroString = tokens[1].Split('\\'); keyNames.Add(tokens[0]); km = new KeyMacro { macroName = tokens[0], macroString = macroString.ToList() }; MacroKeyBinds.Add(km); } } }
public bool Initialize() { LexicalAnalyzer.UseMacro = false; state = new ProcessState(console); originalState = state; initialiing = true; try { ParserMediator.Initialize(console); if (ParserMediator.HasWarning) { ParserMediator.FlushWarningList(); if (MessageBox.Show("コンフィグファイルに異常があります\nEmueraを終了しますか", "コンフィグエラー", MessageBoxButtons.YesNo) == DialogResult.Yes) { console.PrintSystemLine("コンフィグファイルに異常があり、終了が選択されたため処理を終了しました"); return(false); } } Content.AppContents.LoadContents(); if (Config.UseKeyMacro && !Program.AnalysisMode) { if (File.Exists(Program.ExeDir + "macro.txt")) { if (Config.DisplayReport) { console.PrintSystemLine("macro.txt読み込み中・・・"); } KeyMacro.LoadMacroFile(Program.ExeDir + "macro.txt"); } } if (Config.UseReplaceFile && !Program.AnalysisMode) { if (File.Exists(Program.CsvDir + "_Replace.csv")) { if (Config.DisplayReport) { console.PrintSystemLine("_Replace.csv読み込み中・・・"); } ConfigData.Instance.LoadReplaceFile(Program.CsvDir + "_Replace.csv"); if (ParserMediator.HasWarning) { ParserMediator.FlushWarningList(); if (MessageBox.Show("_Replace.csvに異常があります\nEmueraを終了しますか", "_Replace.csvエラー", MessageBoxButtons.YesNo) == DialogResult.Yes) { console.PrintSystemLine("_Replace.csvに異常があり、終了が選択されたため処理を終了しました"); return(false); } } } } Config.SetReplace(ConfigData.Instance); //ここでBARを設定すれば、いいことに気づいた予感 console.setStBar(Config.DrawLineString); if (Config.UseRenameFile) { if (File.Exists(Program.CsvDir + "_Rename.csv")) { if (Config.DisplayReport || Program.AnalysisMode) { console.PrintSystemLine("_Rename.csv読み込み中・・・"); } ParserMediator.LoadEraExRenameFile(Program.CsvDir + "_Rename.csv"); } else { console.PrintError("csv\\_Rename.csvが見つかりません"); } } if (!Config.DisplayReport) { console.PrintSingleLine(Config.LoadLabel); console.RefreshStrings(true); } gamebase = new GameBase(); if (!gamebase.LoadGameBaseCsv(Program.CsvDir + "GAMEBASE.CSV")) { console.PrintSystemLine("GAMEBASE.CSVの読み込み中に問題が発生したため処理を終了しました"); return(false); } console.SetWindowTitle(gamebase.ScriptWindowTitle); GlobalStatic.GameBaseData = gamebase; ConstantData constant = new ConstantData(gamebase); constant.LoadData(Program.CsvDir, console, Config.DisplayReport); GlobalStatic.ConstantData = constant; TrainName = constant.GetCsvNameList(VariableCode.TRAINNAME); vEvaluator = new VariableEvaluator(gamebase, constant); GlobalStatic.VEvaluator = vEvaluator; idDic = new IdentifierDictionary(vEvaluator.VariableData); GlobalStatic.IdentifierDictionary = idDic; StrForm.Initialize(); VariableParser.Initialize(); exm = new ExpressionMediator(this, vEvaluator, console); GlobalStatic.EMediator = exm; labelDic = new LabelDictionary(); GlobalStatic.LabelDictionary = labelDic; HeaderFileLoader hLoader = new HeaderFileLoader(console, idDic, this); LexicalAnalyzer.UseMacro = false; if (!hLoader.LoadHeaderFiles(Program.ErbDir, Config.DisplayReport)) { console.PrintSystemLine("ERHの読み込み中にエラーが発生したため処理を終了しました"); return(false); } LexicalAnalyzer.UseMacro = idDic.UseMacro(); ErbLoader loader = new ErbLoader(console, exm, this); if (Program.AnalysisMode) { noError = loader.loadErbs(Program.AnalysisFiles, labelDic); } else { noError = loader.LoadErbFiles(Program.ErbDir, Config.DisplayReport, labelDic); } initSystemProcess(); initialiing = false; } catch (Exception e) { handleException(e, null, true); console.PrintSystemLine("初期化中に致命的なエラーが発生したため処理を終了しました"); return(false); } if (labelDic == null) { return(false); } state.Begin(BeginType.TITLE); GC.Collect(); return(true); }
/* Creates the custom macro saving it out to the custom macro file list and updating the custom macro loaded data list */ private void createAndSaveMacro(object sender, RoutedEventArgs e) { string macrostring = ""; string customName = ""; try { if (customMacroName.Text != null && customMacroName.Text != "") { customName = customMacroName.Text; if (customName.Length <= 0 || customName.Length > 100) { throw new Exception("Invalid Name length must be between 1 and 100"); } } else { throw new Exception("Macro name must not be empty."); } macrostring = MacroStringTxt.Text; tryLexMacroString(macrostring); if (!model.keyNames.Contains(customName)) { KeyMacro km = new KeyMacro { macroName = customName, macroString = macro }; model.MacroKeyBinds.Add(km); using (StreamWriter writer = File.AppendText(mainwindow.macroFolderPath + Path.DirectorySeparatorChar + MacrosTextFile)) { string ms = ""; for (int t = 0; t < km.macroString.Count; t++) { if (t == km.macroString.Count - 1) { ms += km.macroString[t].ToString(); } else { ms += km.macroString[t].ToString() + "\\"; } } writer.WriteLine(km.macroName + "," + ms); } reset(); NavigationService.Navigate(mainwindow.bindingEditorPage); } else { throw new Exception("Macro name must be unique."); } } catch (Exception err) { MessageBox.Show("Error: " + err.Message); return; } }
/// <summary> /// 初期処理を行います /// 初期化に失敗した場合などは false を返すとプラグインが破棄されます /// この段階ではまだ他のプラグインに配置されていないため、コンポーネントのサイズなどは取得できません /// </summary> /// <returns>false:初期化失敗。プラグインが破棄されます。</returns> public bool Initialize(PluginCreateParam param) { //プラグインマネージャーを保持します _pluginManager = PluginManager.GetInstance(); //プロパティファイルを読み込みます _property.Load(param.PropertyPath); //共通カラーデータを取得します _colorData = (ColorData)_pluginManager.CommonData[CommonDataKeys.ColorData]; if (_colorData == null) { _colorData = new ColorData(); } //テキストボックスを初期化します txtMain.Initialize( _property["font", "name"], StringUtils.ToFloat(_property["font", "size"]) ); //テキストボックスのドラッグ&ドロップ対応 txtMain.AllowDrop = true; //D&Dを許可します txtMain.DragEnter += TxtMain_DragEnter; txtMain.DragDrop += TxtMain_DragDrop; //(設定したのを忘れなければデザイン時にプロパティで設定しても問題ありません) //テキストボックスのテキストを初期化します txtMain.Clear(); //Modified は false になる //変更なしにします txtMain.Modified = false; //キー操作マクロの初期設定 _keyMacro = new KeyMacro(txtMain); //ポップアップメニューを追加します AddPopupMenuItem(); //参照用テキストボックスを初期化します txtSplit.Initialize(txtMain.Font.Name, txtMain.Font.Size); txtSplit.ReadOnly = true; //読込専用 txtSplit.BackColor = Color.FromArgb(0xf0, 0xf0, 0xf0); //見出しリストを初期化します titleListbox.TargetTextbox = txtMain; titleListbox.TitleCharList = new [] { _property["title_list", "level_1"], _property["title_list", "level_2"], _property["title_list", "level_3"], }.ToList <string>(); titleListbox.ForeColor = _colorData.ForeColor; //文字の色 titleListbox.BackColor = _colorData.BackColor; //背景色 //3ペイン用のスプリットコンテナーにコントロールを配置します splitContainer.SetControl(titleListbox, txtSplit, txtMain); splitContainer.PanelLeftVisible = false; splitContainer.PanelTopVisible = false; splitContainer.Dock = DockStyle.Fill; titleListbox.Dock = DockStyle.Fill; txtSplit.Dock = DockStyle.Fill; txtMain.Dock = DockStyle.Fill; /**************************************** * * ファイル読み込み * ****************************************/ //初期化パラメーターを取得します var path = param.Path; var encoding = param["encoding"] as Encoding; var is_binary = param.ToBool("is_binary"); var textFile = param["file"] as IFile; //ファイルオブジェクトが未指定の場合は、生成します if (textFile == null) { if (is_binary) { textFile = new BinaryFile(); } else { textFile = new TextFile(); ((TextFile)textFile).TextEncoding = encoding; } } //テキストファイルを読み込みます textFile.Path = path; this.LoadFile(textFile); //BOMにより自動的に文字コードが変更された場合は、警告を表示します if (this.TargetFile is TextFile targetFile) { if (encoding != null) { //文字コードが指定されていた場合 if (encoding.CodePage != targetFile.TextEncoding.CodePage) { __.ShowWarnMsgBox("自動判別により文字コードを変更しました。"); } } } return(true); }
private void play(KeyMacro macro) { foreach (var rec in macro.Records) { if (rec.Wait > 0) { Thread.Sleep(rec.Wait); } switch (rec.Key) { case Keys.LButton: if (rec.Down) { sim.Mouse.LeftButtonDown(); } else { sim.Mouse.LeftButtonUp(); } break; case Keys.RButton: if (rec.Down) { sim.Mouse.RightButtonDown(); } else { sim.Mouse.RightButtonUp(); } break; case Keys.MButton: break; case Keys.XButton1: if (rec.Down) { sim.Mouse.XButtonDown(1); } else { sim.Mouse.XButtonUp(1); } break; case Keys.XButton2: if (rec.Down) { sim.Mouse.XButtonDown(2); } else { sim.Mouse.XButtonUp(2); } break; default: if (rec.Down) { sim.Keyboard.KeyDown((WindowsInput.Native.VirtualKeyCode)rec.Key); } else { sim.Keyboard.KeyUp((WindowsInput.Native.VirtualKeyCode)rec.Key); } break; } } lastPlayed = Environment.TickCount; }
public void PlayMacro(KeyMacro macro) { thread = new Thread(() => play(macro)); thread.Start(); }