/// <summary> /// 鼠标点击事件 /// </summary> void Hook_OnMouseActivity(object sender, MouseEventArgs e) { SelectedHwnd = FindWindowInfo.GetWindowHWND(e.X, e.Y); string gameName = FindWindowInfo.GetWindowName(SelectedHwnd); int pid = FindWindowInfo.GetProcessIDByHWND(SelectedHwnd); if (Process.GetCurrentProcess().Id != pid) { ProcessInfoLabel.Text = "[实时]" + gameName + "—" + pid; } hook.Stop(); WindowChooseBtn.BtnText = "选择窗口"; }
/// <summary> /// 鼠标点击事件 /// </summary> void Hook_OnMouseActivity(object sender, MouseEventArgs e) { int hwnd = FindWindowInfo.GetWindowHWND(e.X, e.Y); string gameName = FindWindowInfo.GetWindowName(hwnd); int pid = FindWindowInfo.GetProcessIDByHWND(hwnd); if (Process.GetCurrentProcess().Id != pid) { ProcessInfoLabel.Text = "[实时]" + gameName + "—" + pid; bool flag = false; for (int i = 0; i < processList.Count; i++) { KeyValuePair <string, string> pkvp = processList[i]; if (pkvp.Key == pid.ToString()) { SystemProcessCombox.SelectedIndex = i; flag = true; break; } } if (flag == false) { //打开这个窗口后再打开游戏的情况 ReNewSystemProcessCombox(); for (int i = 0; i < processList.Count; i++) { KeyValuePair <string, string> pkvp = processList[i]; if (pkvp.Key == pid.ToString()) { SystemProcessCombox.SelectedIndex = i; flag = true; break; } } } gamePID = pid; hook.Stop(); SelectGameWindowBtn.BtnText = "选择窗口"; } }
/// <summary> /// OCR:鼠标点击的挂载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Hook_OnMouseActivity(object sender, MouseEventArgs e) { if (Common.TransMode == 2) { //OCR方式下单击鼠标进行更新 //先判断是单窗口还是全屏幕,如果是单窗口再判断是不是在游戏窗口中点的 if ((Common.isAllWindowCap == true && Process.GetCurrentProcess().Id != FindWindowInfo.GetProcessIDByHWND(FindWindowInfo.GetWindowHWND(e.X, e.Y))) || Common.OCRWinHwnd == (IntPtr)FindWindowInfo.GetWindowHWND(e.X, e.Y)) { if (IsOCRingFlag == false) { IsOCRingFlag = true; ThreadPool.QueueUserWorkItem(state => { int j = 0; for (; j < 3; j++) { Thread.Sleep(Common.OCRdelay); Image img = ScreenCapture.GetWindowRectCapture(Common.OCRWinHwnd, Common.OCRrec, Common.isAllWindowCap); string ret = BaiduGeneralOCRBasic.BaiduGeneralBasicOCR(img, Common.OCRsrcLangCode); string srcText = ""; BaiduOCRresOutInfo oinfo = JsonConvert.DeserializeObject <BaiduOCRresOutInfo>(ret); if (oinfo.words_result != null) { for (int i = 0; i < oinfo.words_result_num; i++) { srcText = srcText + oinfo.words_result[i].words + "\n"; } } if (srcText != "") { GameTranslateAuto(srcText, Common.srcLang, Common.desLang); srcTextLabel.BeginInvoke(new Action(() => { srcTextLabel.Text = srcText; })); firstTransTextLabel.BeginInvoke(new Action(() => { firstTransTextLabel.Text = firstTransText; })); secondTransTextLabel.BeginInvoke(new Action(() => { secondTransTextLabel.Text = secondTransText; })); Common.AddHistoryText(srcText, firstTransText, secondTransText); IsOCRingFlag = false; break; } } if (j == 3) { srcTextLabel.BeginInvoke(new Action(() => { srcTextLabel.Text = "[OCR]识别三次均为空,请自行刷新!"; })); IsOCRingFlag = false; } }); } } } }