Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:baykovr/AVPI into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Baykov committed Mar 8, 2017
2 parents 2487c5e + cd69a08 commit ac78e81
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion GAVPI/GAVPI/Core/Engine/InputEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ private void phraseRecognized(object sender, SpeechRecognizedEventArgs e)
{
string recognized_value = e.Result.Text;

// Implemented via predicates.
if (!GAVPI.Profile.IsAssociatedProcessFocused())
return;

GAVPI.Profile.Profile_Triggers.Find(trigger => trigger.value == recognized_value).run();

//equivilent code below for reference.
Expand Down
25 changes: 25 additions & 0 deletions GAVPI/GAVPI/Core/Profile/Profile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
Expand Down Expand Up @@ -487,6 +489,29 @@ public string GetAssociatedProcess()
} // public string GetAssociatedProcess()


//
// public bool IsAssociatedProcessFocused()
//
// Check if the associated process is currently focused.
//

public bool IsAssociatedProcessFocused()
{

// If we don't have a process associated, skip this check.
if (AssociatedProcess == null) return true;

IntPtr handle = Win32_APIs.GetForegroundWindow();
uint pid = 0;
Win32_APIs.GetWindowThreadProcessId(handle, out pid);
Process proc = Process.GetProcessById((int)pid);
String procPath = proc.MainModule.FileName;

return String.Compare(Path.GetFullPath(procPath),
Path.GetFullPath(AssociatedProcess),
StringComparison.InvariantCultureIgnoreCase) == 0;

} // public bool IsAssocaitedProcessFocused()

//
// public void SetAssociatedProcess( string )
Expand Down
6 changes: 6 additions & 0 deletions GAVPI/GAVPI/Util/Win32_APIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ internal class Win32_APIs
[DllImport("user32")]
public static extern bool PostMessage( IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam );

[DllImport("user32")]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

// Win32 parameter constants:

public const int HWND_BROADCAST = 0xffff;
Expand Down

0 comments on commit ac78e81

Please sign in to comment.