模拟CTRL+C

  keybd_event(VK_CONTROL, 0, 0, 0);
  keybd_event(Byte('C'), 0, 0, 0);
  keybd_event(Byte('C'), 0, KEYEVENTF_KEYUP, 0);
  keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);

 

 

 

Delphi 键盘码表
 
VK_LBUTTON = 1;
VK_RBUTTON = 2;
VK_CANCEL = 3;
VK_MBUTTON = 4; { NOT contiguous with L & RBUTTON }
VK_BACK = 8;
VK_TAB = 9;
VK_CLEAR = 12;
VK_RETURN = 13;
VK_SHIFT = $10;
VK_CONTROL = 17;
VK_MENU = 18;
VK_PAUSE = 19;
VK_CAPITAL = 20;
VK_KANA = 21;
VK_HANGUL = 21;
VK_JUNJA = 23;
VK_FINAL = 24;
VK_HANJA = 25;
VK_KANJI = 25;
VK_CONVERT = 28;
VK_NONCONVERT = 29;
VK_ACCEPT = 30;
VK_MODECHANGE = 31;
VK_ESCAPE = 27;
VK_SPACE = $20;
VK_PRIOR = 33;
VK_NEXT = 34;
VK_END = 35;
VK_HOME = 36;
VK_LEFT = 37;
VK_UP = 38;
VK_RIGHT = 39;
VK_DOWN = 40;
VK_SELECT = 41;
VK_PRINT = 42;
VK_EXECUTE = 43;
VK_SNAPSHOT = 44;
VK_INSERT = 45;
VK_DELETE = 46;
VK_HELP = 47;
{ VK_0 thru VK_9 are the same as ASCII '0' thru '9' ($30 - $39) }
{ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' ($41 - $5A) }
VK_LWIN = 91;
VK_RWIN = 92;
VK_APPS = 93;
VK_NUMPAD0 = 96;
VK_NUMPAD1 = 97;
VK_NUMPAD2 = 98;
VK_NUMPAD3 = 99;
VK_NUMPAD4 = 100;
VK_NUMPAD5 = 101;
VK_NUMPAD6 = 102;
VK_NUMPAD7 = 103;
VK_NUMPAD8 = 104;    
VK_NUMPAD9 = 105;
VK_MULTIPLY = 106;
VK_ADD = 107;
VK_SEPARATOR = 108;
VK_SUBTRACT = 109;
VK_DECIMAL = 110;
VK_DIVIDE = 111;
VK_F1 = 112;
VK_F2 = 113;
VK_F3 = 114;
VK_F4 = 115;
VK_F5 = 116;
VK_F6 = 117;
VK_F7 = 118;
VK_F8 = 119;
VK_F9 = 120;
VK_F10 = 121;
VK_F11 = 122;
VK_F12 = 123;
VK_F13 = 124;
VK_F14 = 125;
VK_F15 = 126;
VK_F16 = 127;
VK_F17 = 128;
VK_F18 = 129;
VK_F19 = 130;
VK_F20 = 131;
VK_F21 = 132;
VK_F22 = 133;
VK_F23 = 134;
VK_F24 = 135;
VK_NUMLOCK = 144;
VK_SCROLL = 145;
{ VK_L & VK_R - left and right Alt, Ctrl and Shift virtual keys.
Used only as parameters to GetAsyncKeyState() and GetKeyState().
No other API or message will distinguish left and right keys in this way. }
VK_LSHIFT = 160;
VK_RSHIFT = 161;
VK_LCONTROL = 162;
VK_RCONTROL = 163;
VK_LMENU = 164;
VK_RMENU = 165;
VK_PROCESSKEY = 229;
VK_ATTN = 246;
VK_CRSEL = 247;
VK_EXSEL = 248;
VK_EREOF = 249;
VK_PLAY = 250;
VK_ZOOM = 251;
VK_NONAME = 252;
VK_PA1 = 253;
VK_OEM_CLEAR = 254;

在 C# 中,如果你通过 `Process` 类打开了 WildFly 的 standalone.bat 启动脚本,想要模拟发送 `Ctrl+C` 关闭 Java 服务,你可以使用 `StreamWriter` 和 `Powershell` 来实现。这是因为直接对启动进程发送 Ctrl+C 可能不会像预期那样工作,因为有些程序可能会捕获并忽略这个信号。以下是步骤: 1. 首先,创建一个新的 `ProcessStartInfo` 对象,并指定要运行的 `standalone.bat` 脚本的路径。 ```csharp using System.Diagnostics; string batFilePath = "path_to_your_standalone.bat"; ProcessStartInfo psi = new ProcessStartInfo(batFilePath); psi.UseShellExecute = false; // 确保以非交互模式运行 psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; ``` 2. 创建一个 `Process` 实例并开始执行命令。 ```csharp Process process = new Process(); process.StartInfo = psi; process.Start(); ``` 3. 使用 `StreamWriter` 发送 `Ctrl+C` 到 `stdin` (标准输入)。这通常表示键盘输入。 ```csharp byte[] inputBuffer = Encoding.ASCII.GetBytes("\03"); // Ctrl+C 的 ASCII 编码 process.StandardInput.Write(inputBuffer); ``` 4. 等待一段短时间,让系统处理这个信号(例如 500 毫秒),然后关闭 `StandardInput`。 ```csharp System.Threading.Thread.Sleep(500); // 500毫秒的等待 process.StandardInput.Close(); ``` 5. 最后,可以检查 `StandardOutput` 或 `StandardError` 获取任何可能的响应信息。 注意:这种方法可能因 WildFly 的设置而异,如果它有特殊的处理机制来忽略 `Ctrl+C` 或者需要更复杂的交互才能终止,可能需要进一步的研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值