Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 模拟在非活动过程中按住一个键_C#_.net - Fatal编程技术网

C# 模拟在非活动过程中按住一个键

C# 模拟在非活动过程中按住一个键,c#,.net,C#,.net,我在谷歌上搜索,找不到任何可行的。。。到目前为止,最好的代码如下: Process proc = Process.GetProcessesByName("firefox")[0]; IntPtr ptrFF = proc.Handle; SetForegroundWindow(ptrFF); SendKeys.SendWait("{F1}"); 但这并不是我所需要的。这将Firefox带到前端,并发送一次密钥,但我需要按住密钥,并在非活动进程/最小化窗口上工作。我该怎么做呢?即使手动按F1,f

我在谷歌上搜索,找不到任何可行的。。。到目前为止,最好的代码如下:

Process proc = Process.GetProcessesByName("firefox")[0];
IntPtr ptrFF = proc.Handle;
SetForegroundWindow(ptrFF);
SendKeys.SendWait("{F1}");

但这并不是我所需要的。这将Firefox带到前端,并发送一次密钥,但我需要按住密钥,并在非活动进程/最小化窗口上工作。我该怎么做呢?

即使手动按F1,firefox也不会响应!请阅读我所写的内容-这是一个示例代码,尽可能是最好的,但与我所需要的并不接近。@ojek-它可能是示例代码,但使用一个不起任何作用的键,您无法证明它的行为不正确。从这里我们可以看出,事实上,它正确地发送了一个
F1
,FF会忽略它。如果我告诉你这个代码运行的是一个矩阵,你会相信我吗?有清晰可见的功能
SetForeGroundIndow(ptrFF),它不需要任何解释,还有一个
SendWait()
函数,它与进程没有任何连接。哦,好吧。我需要类似的东西来保存密钥并连接到进程。带wm_keydown的pinvoke postmessage