在 Windows 控制台应用程序中,可以ctrl+c使用以下命令捕获按下的按钮:
#include <stdio.h>\n#include <signal.h>\n\nvoid SigInt_Handler(int n_signal)\n{\n printf("interrupted\\n");\n}\n\nint main(int n_arg_num, const char **p_arg_list)\n{\n signal(SIGINT, &SigInt_Handler);\n getchar(); // wait for user intervention\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\xc3\x97这很有效,但如果用户按下关闭控制台窗口的十字键,它根本不起作用。有这方面的信号吗?
我需要这个的原因是我有一个 CUDA 应用程序,如果在计算某些内容时关闭它,它往往会导致计算机崩溃。该代码是多平台的,因此我更喜欢使用信号而不是SetConsoleCtrlHandler. 有办法吗?
我正在设计一个从Kinect读取手势并做出一些动作的系统.我试图包括系统,以便能够将HotKey发送到应用程序.我的系统是用c ++编写的,但UI是用C++ .net编写的.我已经能够从UI部分使用SendKeys,它确实有效.
是否有Win32等价物,所以我可以在我的系统中使用它?
提前致谢!
我尝试生成子进程 - vvp (https://linux.die.net/man/1/vvp)。在某个时间,我需要发送CTRL+C到该进程。我预计模拟会被中断,并且我会收到交互式提示。之后我可以通过向子进程发送命令来继续模拟。所以,我尝试了这样的事情:
var child = require('child_process');
var fs = require('fs');
var vcdGen = child.spawn('vvp', ['qqq'], {});
vcdGen.stdout.on('data', function(data) {
console.log(data.toString())
});
setTimeout(function() {
vcdGen.kill('SIGINT');
}, 400);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,子进程被停止。我也尝试vcdGen.stdin.write('\x03')过,vcdGen.kill('SIGINT');但它不起作用。
也许是因为Windows?有什么方法可以实现与我在 cmd 中获得的相同的行为吗?
我制作了一个打开某个程序的程序,然后在 x 时间后Ctrl+C它。
我现在正在使用这个[System.Windows.Forms.SendKeys]::SendWait("^{c}")。这个目标是某个窗口还是随机发送到当前窗口?
如何将其更改为某个窗口?
这是我的代码:
Write-Host "Safe Botting V0.1"
Write-Host "Initializing..."
Start-Sleep -s 3
Write-Host "Program started successfully with no errors."
While($true)
{
Write-Host "Starting bot..."
Start-Sleep -s 3
Start-Process -FilePath E:\Documents\bot.exe
Write-Host "Bot started successfully"
$rnd = Get-Random -Minimum 1800 -Maximum 10800
Write-Host "The bot will run for:"
Write-Host $rnd
Start-Sleep -s $rnd
Write-Host "Bot will now stop!"
[System.Windows.Forms.SendKeys]::SendWait("^{c}")
Write-Host "Bot terminated"
Write-Host "Starting cooldown time"
$rnb = Get-Random -Minimum 14400 -Maximum …Run Code Online (Sandbox Code Playgroud)