public void KeyUp(String args) { //if (String.IsNullOrWhiteSpace(args)) return; if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { VirtualKeyCode KeyCode = Uint_Regex.IsMatch(args) ? (VirtualKeyCode)Convert.ToInt32(args) : (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), args, true); if (InputSimulator == null) { InputSimulator = new InputSimulator(); } InputSimulator.Keyboard.KeyUp(KeyCode); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public void ActivateWindow(String args) { if (!HasActivePresentation()) { return; } if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(args)) { String ErrorMessage = "参数 " + args + " 格式输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } int Index = Convert.ToInt32(args); if (Index < 1 || Index > Application.Windows.Count) { String ErrorMessage = "索引 " + Index + " 超出 Windows 范围:" + Application.Windows.Count; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } Application.Windows[Index].Activate(); }
public void Export(String path, String width, String height) { if (!HasActivePresentation()) { return; } String Path = String.IsNullOrWhiteSpace(path) ? ActivePresentation.Path + "/" + ActivePresentation.Name.Split('.')[0] : path; //目录不存在则创建 if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } int ScaleWidth = String.IsNullOrWhiteSpace(width) || !Uint_Regex.IsMatch(width) ? 0 : Convert.ToInt32(width); int ScaleHeight = String.IsNullOrWhiteSpace(height) || !Uint_Regex.IsMatch(height) ? 0 : Convert.ToInt32(height); try { ActivePresentation.Export(Path.Replace("/", "\\"), "jpg", ScaleWidth, ScaleHeight); } catch (Exception e) { WriteError("导出失败:" + e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public void VerticalScroll(String args) { if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(args)) { String ErrorMessage = "参数 " + args + " 输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { int scrollAmountInClicks = Convert.ToInt32(args); if (InputSimulator == null) { InputSimulator = new InputSimulator(); } InputSimulator.Mouse.VerticalScroll(scrollAmountInClicks); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public void Sleep(String args) { if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(args)) { String ErrorMessage = "参数 " + args + " 格式输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { int millsecondsTimeout = Convert.ToInt32(args); Thread.Sleep(millsecondsTimeout); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public void ExportSlide(String index, String path, String width, String height) { if (!HasActivePresentation()) { return; } if (String.IsNullOrWhiteSpace(index)) { String ErrorMessage = "参数 index 输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(index)) { String ErrorMessage = "参数 " + index + " 格式输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } int Index = Convert.ToInt32(index); if (Index < 1 || Index > ActivePresentation.Slides.Count) { String ErrorMessage = "索引 " + Index + " 超出 PowerPoint 文档页面范围:" + ActivePresentation.Slides.Count; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } String Path = String.IsNullOrWhiteSpace(path) ? ActivePresentation.Path + "/" + ActivePresentation.Name.Split('.')[0] : path; //目录不存在则创建 if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } int ScaleWidth = String.IsNullOrWhiteSpace(width) || !Uint_Regex.IsMatch(width) ? 0 : Convert.ToInt32(width); int ScaleHeight = String.IsNullOrWhiteSpace(height) || !Uint_Regex.IsMatch(height) ? 0 : Convert.ToInt32(height); try { ActivePresentation.Slides[Index].Export(Path.Replace("/", "\\"), "jpg", ScaleWidth, ScaleHeight); } catch (Exception e) { WriteError("导出失败:" + e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public Boolean OutputFormat(String args) { if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return(false); } try { _OutputFormat = Uint_Regex.IsMatch(args) ? (ConsoleOutputFormat)Convert.ToInt32(args) : (ConsoleOutputFormat)Enum.Parse(typeof(ConsoleOutputFormat), args, true); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); return(false); } return(true); }
public void GotoClick(String args) { if (!HasActivePresentation()) { return; } if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(args)) { String ErrorMessage = "参数 " + args + " 格式输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { int Index = Convert.ToInt32(args); int ClickCount = ActivePresentation.SlideShowWindow.View.GetClickCount(); if (Index < 0 || Index > ClickCount) { String ErrorMessage = "索引 " + Index + " 超出 PowerPoint 文档当前页面范围:" + ClickCount; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } ActivePresentation.SlideShowWindow.View.GotoClick(Index); } catch (Exception) { String ErrorMessage = "非演示模式下的 PowerPoint 应用文档,操作失败"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); } }
//[CommandLine("aws", "ApplicationWindowState", "编辑模式下有效,设置 PowerPoint 应用窗体状态,参考:1:ppWindowNormal, 2:ppWindowMinimized, 3:ppWindowMaximized")] public void ApplicationWindowState(String args) { if (!HasActivePresentation()) { return; } if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数 " + args + " 输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { Application.WindowState = Uint_Regex.IsMatch(args) ? (PPT.PpWindowState)Convert.ToInt32(args) : (PPT.PpWindowState)Enum.Parse(typeof(PPT.PpWindowState), args, true); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }
public void GotoPage(String args) { if (!HasActivePresentation()) { return; } if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } if (!Uint_Regex.IsMatch(args)) { String ErrorMessage = "参数 " + args + " 格式输入错误"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } int Index = Convert.ToInt32(args); if (Index < 1 || Index > ActivePresentation.Slides.Count) { String ErrorMessage = "索引 " + Index + " 超出 PowerPoint 文档页面范围:" + ActivePresentation.Slides.Count; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { ActivePresentation.SlideShowWindow.View.GotoSlide(Index); } catch (Exception) { ActivePresentation.Slides[Index].Select(); } }
public void ModifiedKeyStroke(String args) { //if (String.IsNullOrWhiteSpace(args)) return; if (String.IsNullOrWhiteSpace(args)) { String ErrorMessage = "参数输入错误,不能为空"; WriteError(ErrorMessage, _OutputFormat, MethodBase.GetCurrentMethod()); return; } try { String[] values = args.Split('+')[0].Split('|'); VirtualKeyCode[] modifierKeyCode = new VirtualKeyCode[values.Length]; for (int i = 0; i < values.Length; i++) { modifierKeyCode[i] = Uint_Regex.IsMatch(values[i]) ? (VirtualKeyCode)Convert.ToInt32(values[i]) : (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), values[i], true); } values = args.Split('+')[1].Split('|'); VirtualKeyCode[] keyCode = new VirtualKeyCode[values.Length]; for (int i = 0; i < values.Length; i++) { keyCode[i] = Uint_Regex.IsMatch(values[i]) ? (VirtualKeyCode)Convert.ToInt32(values[i]) : (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), values[i], true); } if (InputSimulator == null) { InputSimulator = new InputSimulator(); } InputSimulator.Keyboard.ModifiedKeyStroke(modifierKeyCode, keyCode); } catch (Exception e) { WriteError(e.Message, _OutputFormat, MethodBase.GetCurrentMethod()); } }