Commit 83a4f096 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

clinet receives information in form and also it receives information about mouse and keyboard

parent 9cb26e25
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9BA81346-7892-448B-B562-3B1F9F2A3CF7}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FaceDetectionApp</RootNamespace>
<AssemblyName>FaceDetectionApp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UserActivityHook.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FaceDetectionMain2\FaceDetectionMain.csproj">
<Project>{1b9679b2-5d28-4451-9538-671f32d3a4bd}</Project>
<Name>FaceDetectionMain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9BA81346-7892-448B-B562-3B1F9F2A3CF7}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FaceDetectionApp</RootNamespace>
<AssemblyName>FaceDetectionApp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserActivityHook.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FaceDetectionMain2\FaceDetectionMain.csproj">
<Project>{1b9679b2-5d28-4451-9538-671f32d3a4bd}</Project>
<Name>FaceDetectionMain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using gma.System.Windows;
namespace FaceDetectionApp
{
public partial class Form1 : Form
{
UserActivityHook actHook;
public Form1()
{
InitializeComponent();
#region faceDetector Initializations
FaceDetector.Instance.FrameCapturedEvent += FrameCallback;
FaceDetector.Instance.FaceDetectedEvent += FaceDetectedCallback;
FaceDetector.Instance.FaceLostEvent += FaceLostCallback;
FaceDetector.Instance.ActiveWindowChanged += F_ActiveWindowChanged;
FaceDetector.Instance.AttentionChecker += AttentoinCheck;
textBox1.Text = FaceDetector.Instance.GetActiveWindowTitle().ToString();
#endregion
#region mouseHook and keyboardHook Initialization
actHook = new UserActivityHook(); // crate an instance with global hooks
// hang on events
actHook.OnMouseActivity += new MouseEventHandler(MouseMoved);
actHook.KeyDown += new KeyEventHandler(MyKeyDown);
actHook.KeyPress += new KeyPressEventHandler(MyKeyPress);
actHook.KeyUp += new KeyEventHandler(MyKeyUp);
actHook.Start();
#endregion
}
#region mouse/keyboard events for hook
public void MouseMoved(object sender, MouseEventArgs e)
{
mouseLabel.Text = String.Format("Last mouse event: " + System.DateTime.Now.ToString());
if (e.Clicks > 0)
String.Format("Last mouse event: " + System.DateTime.Now.ToString());
}
public void MyKeyDown(object sender, KeyEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
}
public void MyKeyPress(object sender, KeyPressEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
}
public void MyKeyUp(object sender, KeyEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
}
#endregion
private void AttentoinCheck()
{
bool attention = (FaceDetector.Instance.HasFace) && (FaceDetector.Instance.isCurrentWindowTheApp);
lblAtt.Text = "Attention: " + attention.ToString();
}
private void F_ActiveWindowChanged(object sender, WindowTitle windowHeader, string Windows, IntPtr hwnd)
{
textBox1.Text = "CURRENT WINDOW:" + windowHeader.Title + "\r\n\r\nVISIBLE WINDOWS:\r\n" + Windows;
if (!windowHeader.Title.Equals("Form1"))
{
FaceDetector.Instance.isCurrentWindowTheApp = false;
}
else
{
FaceDetector.Instance.isCurrentWindowTheApp = true;
}
AttentoinCheck();
}
#region face detection methods
private void FaceDetectedCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceDetectedCallback));
lblFace.Text = "Face Detected at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FaceLostCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceLostCallback));
lblFace.Text = "Face Lost at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FrameCallback(Bitmap b, Rectangle[] faces)
{
if (b != null)
pictureBox1.Image = b;
}
#endregion
}
}
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using gma.System.Windows;
namespace FaceDetectionApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region faceDetector Initializations
FaceDetector.Instance.FrameCapturedEvent += FrameCallback;
FaceDetector.Instance.FaceDetectedEvent += FaceDetectedCallback;
FaceDetector.Instance.FaceLostEvent += FaceLostCallback;
FaceDetector.Instance.ActiveWindowChanged += F_ActiveWindowChanged;
FaceDetector.Instance.AttentionChecker += AttentoinCheck;
textBox1.Text = FaceDetector.Instance.GetActiveWindowTitle().ToString();
#endregion
UserActivityHook actHook;
#region mouseHook and keyboardHook Initialization
actHook = new UserActivityHook(); // crate an instance with global hook // hang on events
actHook.OnMouseActivity += new MouseEventHandler(MouseMoved);
actHook.OnMouseActivity += new MouseEventHandler(Program.mouseUpdate);
actHook.KeyDown += new KeyEventHandler(MyKeyDown);
actHook.KeyDown += new KeyEventHandler(Program.keyBoardUpdate1);
actHook.KeyPress += new KeyPressEventHandler(MyKeyPress);
actHook.KeyPress += new KeyPressEventHandler(Program.keyBoardUpdate2);
actHook.KeyUp += new KeyEventHandler(MyKeyUp);
actHook.KeyUp += new KeyEventHandler(Program.keyBoardUpdate1);
actHook.Start();
#endregion
}
#region mouse/keyboard events for hook
public void MouseMoved(object sender, MouseEventArgs e)
{
mouseLabel.Text = String.Format("Last mouse event: " + System.DateTime.Now.ToString());
if (e.Clicks > 0)
{
String.Format("Last mouse event: " + System.DateTime.Now.ToString());
}
FaceDetector.Instance.lastMouseEvent = System.DateTime.Now;
}
public void MyKeyDown(object sender, KeyEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
FaceDetector.Instance.lastKeyboardEvent = System.DateTime.Now;
}
public void MyKeyPress(object sender, KeyPressEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
FaceDetector.Instance.lastKeyboardEvent = System.DateTime.Now;
}
public void MyKeyUp(object sender, KeyEventArgs e)
{
keyboardLabel.Text = String.Format("Last keyboard event: " + System.DateTime.Now.ToString());
FaceDetector.Instance.lastKeyboardEvent = System.DateTime.Now;
}
#endregion
private void AttentoinCheck()
{
bool attention = (FaceDetector.Instance.HasFace) && (FaceDetector.Instance.isCurrentWindowTheApp);
lblAtt.Text = "Attention: " + attention.ToString();
}
private void F_ActiveWindowChanged(object sender, WindowTitle windowHeader, string Windows, IntPtr hwnd)
{
textBox1.Text = "CURRENT WINDOW:" + windowHeader.Title + "\r\n\r\nVISIBLE WINDOWS:\r\n" + Windows;
if (!windowHeader.Title.Equals("Form1"))
{
FaceDetector.Instance.isCurrentWindowTheApp = false;
}
else
{
FaceDetector.Instance.isCurrentWindowTheApp = true;
}
AttentoinCheck();
}
#region face detection methods
private void FaceDetectedCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceDetectedCallback));
lblFace.Text = "Face Detected at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FaceLostCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceLostCallback));
lblFace.Text = "Face Lost at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FrameCallback(Bitmap b, Rectangle[] faces)
{
if (b != null)
pictureBox1.Image = b;
}
#endregion
}
}
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//https://msdn.microsoft.com/en-us/library/bb546085.aspx Named Pipes
//http://www.codeproject.com/Articles/10649/An-Introduction-to-Socket-Programming-in-NET-using
//https://msdn.microsoft.com/en-us/library/system.net.sockets.multicastoption(v=vs.110).aspx
//https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms633516(v=vs.85).aspx
namespace FaceDetectionApp
{
static class Program
{
private static FaceDetector f;
private static TcpListener listener;
private const int LIMIT = 6; //6 concurrent clients
private static List<StreamWriter> sw;
public static JSONMessage JSONMessage;
[STAThread]
static void Main()
{
Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
#region Callbacks
private static void FaceDetectedCallback()
{
try
{
JSONMessage.CurrectFaceState = FaceState.Face;
JSONMessage.CurrentTitle = FaceDetector.Instance.GetActiveWindowTitle();
JSONMessage.VisibleWindows = FaceDetector.Instance.Windows;
//write out to each connected listener
//Console.WriteLine(JSONMessage.ToString());
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
} catch(Exception e) {
Console.WriteLine(e.Message);
}
}
private static void FaceLostCallback()
{
try
{
JSONMessage.CurrectFaceState = FaceState.NoFace;
JSONMessage.CurrentTitle = FaceDetector.Instance.GetActiveWindowTitle();
JSONMessage.VisibleWindows = FaceDetector.Instance.Windows;
//write out to each connected listener
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
} catch (Exception e) {
Console.WriteLine(e.Message);
}
}
private static void ActiveWindowChangedCallback(object sender, WindowTitle windowHeader, string Windows, IntPtr hwnd)
{
try
{
//write out to each connected listener
JSONMessage.CurrentTitle = windowHeader;
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
#endregion
public static void Init()
{
sw = new List<StreamWriter>();
f = new FaceDetector(true);
if (f.IsCapturing) {
f.FaceDetectedEvent += FaceDetectedCallback;
f.FaceLostEvent += FaceLostCallback;
f.ActiveWindowChanged += ActiveWindowChangedCallback;
JSONMessage = new JSONMessage(f.GetActiveWindowTitle(), f.Windows);
#pragma warning disable CS0618 // Type or member is obsolete
listener = new TcpListener(2055);
#pragma warning restore CS0618 // Type or member is obsolete
listener.Start();