这是为windows桌面,不是web..。在C#中使用Visual Studio2013。在Windows7中。
你好,我正在从头开始创建一个"Windows语音识别器“...我工作得很好..。我需要为它做什么,以检查哪些窗口进程是打开的(即记事本,火狐等),然后如果记事本是打开的,做点什么…而不需要亲自调用该操作。比如自动的..。打开记事本...一个警告说“你好记事本”...我关闭记事本“一个动作说”关闭记事本“...我尝试了12948305380453种不同的东西,但我唯一完成的事情是它写了一个数字...当我关闭并重新打开记事本...这个数字是不同的...我需要进程名称...像windows任务管理器中的"notepad.exe”"firefox.exe“...
对不起,我没有任何代码发布,因为我没有一个实际的这一部分…谢谢..。
程序(记事本)将手动打开,因此代码需要不断跟踪任务管理器进程。并在代码中的一个变量中给出结果(例如,字符串"PNAME",这样我就可以在代码的其余部分中使用该变量。
我只需要它告诉我,如果Notepad.exe是开放的不(即对或错),我们喜欢
如果notepad.exe已打开,请执行此操作;如果notepad.exe已关闭,则不执行任何操作
好的..。代码是相当大的。所以我会试着贴出最相关的…
我使用的"usign“是..。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Text;
using System.Windows.Forms;
using System.Threading;我已经初始化了一个语音识别引擎,它不使用windows UI或它的命令(例如,如果我说Open Firefox“它什么也不做,因为它不在他的语法中)”
然后我加载了我自己的语法
private Grammar CreateCustomGrammar()
{
GrammarBuilder GeneralCommands = new GrammarBuilder();
GeneralCommands.Append(new Choices("cut", "copy", "paste", "Read Clipboard", "help", "Close Recognition", "Turn Dictation On", "Read That"));
return new Grammar(GeneralCommands);
recognizer.LoadGrammar(GeneralCommands);
}并为语法中的每个单词添加了一个开关,这样它就知道该怎么做
private void SpeechToAction(string text)
{
DetermineText(text);
switch (text)
{
case "cut":
//cut();
speed();
break;
case "copy":
copy();
break;
case "paste":
paste();
break;
case "Read Clipboard":
readClipboard();
break;
case "Read That":
readThat();
break;
case "Turn Dictation Off":
TurnDictationOff();
break;
case "help":
help();
break;
case "Close Recognition":
Exit();
break;
}
}所有这些工作在后台,如果我想使用另一个应用程序"ie记事本“
但是如果有我想要激活的命令,而“记事本”是前台应用程序...这就是我被卡住的地方
我知道理论..。
它会是这样的
(在我添加的所有代码之前)
//here is the tricky part
IF //notepad is the foreground and var notepadOK == 1
{
private Grammar NEWNAME()
{
GrammarBuilder NEWNAME = new GrammarBuilder();
GeneralCommands.Append(new Choices("Hole notepad", "save"));
return new Grammar(NEWNAME);
var notepadOK = 0
}
}
IF //notepad is NOT in the foreground and notepadOK == 0
{
// unload Notepad Grammar (i remember how to do this part, just cant find //it in the code
}发布于 2014-03-30 02:16:30
为了在.net中查找和处理进程,您应该使用Process类,您可以使用该类列出正在运行的进程并获取有关每个进程的信息
Process.GetProcesses()方法的示例看起来几乎就是您想要的,只是您需要不断地这样做
https://stackoverflow.com/questions/22734815
复制相似问题