Commit 2f713824 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Testing for now

parent 633f57b8
......@@ -46,6 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UserActivityHook.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
......
......@@ -32,7 +32,8 @@
this.lblFace = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.lblAtt = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.mouseLabel = new System.Windows.Forms.Label();
this.keyboardLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
......@@ -50,16 +51,16 @@
this.lblFace.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblFace.Location = new System.Drawing.Point(514, 12);
this.lblFace.Name = "lblFace";
this.lblFace.Size = new System.Drawing.Size(66, 24);
this.lblFace.Size = new System.Drawing.Size(135, 24);
this.lblFace.TabIndex = 1;
this.lblFace.Text = "label1";
this.lblFace.Text = "FaceDetector";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(518, 91);
this.textBox1.Location = new System.Drawing.Point(518, 164);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(331, 276);
this.textBox1.Size = new System.Drawing.Size(331, 203);
this.textBox1.TabIndex = 2;
//
// lblAtt
......@@ -71,21 +72,31 @@
this.lblAtt.TabIndex = 3;
this.lblAtt.Text = "label1";
//
// button2
// mouseLabel
//
this.button2.Location = new System.Drawing.Point(763, 52);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 4;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.mouseLabel.AutoSize = true;
this.mouseLabel.Location = new System.Drawing.Point(515, 85);
this.mouseLabel.Name = "mouseLabel";
this.mouseLabel.Size = new System.Drawing.Size(35, 13);
this.mouseLabel.TabIndex = 4;
this.mouseLabel.Text = "label2";
//
// keyboardLabel
//
this.keyboardLabel.AutoSize = true;
this.keyboardLabel.Location = new System.Drawing.Point(518, 117);
this.keyboardLabel.Name = "keyboardLabel";
this.keyboardLabel.Size = new System.Drawing.Size(35, 13);
this.keyboardLabel.TabIndex = 5;
this.keyboardLabel.Text = "label3";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(861, 379);
this.Controls.Add(this.button2);
this.Controls.Add(this.keyboardLabel);
this.Controls.Add(this.mouseLabel);
this.Controls.Add(this.lblAtt);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.lblFace);
......@@ -104,6 +115,7 @@
private System.Windows.Forms.Label lblFace;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label lblAtt;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label mouseLabel;
private System.Windows.Forms.Label keyboardLabel;
}
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using gma.System.Windows;
namespace FaceDetectionApp
......@@ -17,70 +19,52 @@ namespace FaceDetectionApp
public partial class Form1 : Form
{
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
UserActivityHook actHook;
public Form1()
{
InitializeComponent();
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();
//Declare the mouse hook constant.
//For other hook types, you can obtain these values from Winuser.h in the Microsoft SDK.
public const int WH_MOUSE = 7;
private System.Windows.Forms.Button button1;
static int hHook = 0;
//Declare MouseHookProcedure as a HookProc type.
HookProc MouseHookProcedure;
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();
//Declare the wrapper managed POINT class.
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
}
//Declare the wrapper managed MouseHookStruct class.
[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int hwnd;
public int wHitTestCode;
public int dwExtraInfo;
}
//This is the Import for the SetWindowsHookEx function.
//Use this function to install a thread-specific hook.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);
//This is the Import for the UnhookWindowsHookEx function.
//Call this function to uninstall the hook.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
//This is the Import for the CallNextHookEx function.
//Use this function to pass the hook information to the next hook procedure in chain.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
IntPtr wParam, IntPtr lParam);
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 Form1()
public void MyKeyPress(object sender, KeyPressEventArgs e)
{
InitializeComponent();
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();
button2.Click += button2_Click;
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());
}
private void AttentoinCheck()
{
......@@ -127,65 +111,5 @@ namespace FaceDetectionApp
pictureBox1.Image = b;
}
private void button2_Click(object sender, System.EventArgs e)
{
if (hHook == 0)
{
// Create an instance of HookProc.
MouseHookProcedure = new HookProc(Form1.MouseHookProc);
hHook = SetWindowsHookEx(WH_MOUSE,
MouseHookProcedure,
(IntPtr)0,
AppDomain.GetCurrentThreadId());
//If the SetWindowsHookEx function fails.
if (hHook == 0)
{
MessageBox.Show("SetWindowsHookEx Failed");
return;
}
button2.Text = "UnHook Windows Hook";
}
else
{
bool ret = UnhookWindowsHookEx(hHook);
//If the UnhookWindowsHookEx function fails.
if (ret == false)
{
MessageBox.Show("UnhookWindowsHookEx Failed");
return;
}
hHook = 0;
button1.Text = "Set Windows Hook";
this.Text = "Mouse Hook";
}
}
public static int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
//Marshall the data from the callback.
MouseHookStruct MyMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
if (nCode < 0)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
else
{
//Create a string variable that shows the current mouse coordinates.
String strCaption = "x = " +
MyMouseHookStruct.pt.x.ToString("d") +
" y = " +
MyMouseHookStruct.pt.y.ToString("d");
//You must get the active form because it is a static function.
Form tempForm = Form.ActiveForm;
//Set the caption of the form.
tempForm.Text = strCaption;
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
}
}
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment