Added mouse movement detector, clock in label
This commit is contained in:
parent
404414abea
commit
a9556ba259
@ -14,6 +14,21 @@
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<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|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -65,6 +80,7 @@
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GlobalHooks.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Toolbar.cs">
|
||||
@ -98,7 +114,33 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="media\beep.wav">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- 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">
|
||||
|
66
FemboyWatchdog/GlobalHooks.cs
Normal file
66
FemboyWatchdog/GlobalHooks.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FemboyWatchdog
|
||||
{
|
||||
static class GlobalHooks
|
||||
{
|
||||
public delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public static IntPtr SetHook(LowLevelMouseProc proc)
|
||||
{
|
||||
using (Process curProcess = Process.GetCurrentProcess())
|
||||
using (ProcessModule curModule = curProcess.MainModule)
|
||||
{
|
||||
return SetWindowsHookEx(WH_MOUSE_LL, proc,
|
||||
GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public const int WH_MOUSE_LL = 14;
|
||||
|
||||
public enum MouseMessages
|
||||
{
|
||||
WM_LBUTTONDOWN = 0x0201,
|
||||
WM_LBUTTONUP = 0x0202,
|
||||
WM_MOUSEMOVE = 0x0200,
|
||||
WM_MOUSEWHEEL = 0x020A,
|
||||
WM_RBUTTONDOWN = 0x0204,
|
||||
WM_RBUTTONUP = 0x0205
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MSLLHOOKSTRUCT
|
||||
{
|
||||
public POINT pt;
|
||||
public uint mouseData;
|
||||
public uint flags;
|
||||
public uint time;
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook,
|
||||
LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
|
||||
IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
}
|
||||
}
|
3
FemboyWatchdog/Toolbar.Designer.cs
generated
3
FemboyWatchdog/Toolbar.Designer.cs
generated
@ -19,6 +19,9 @@ namespace FemboyWatchdog
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
|
||||
GlobalHooks.UnhookWindowsHookEx(_hookID);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Media;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Speech.Synthesis;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
@ -14,21 +16,33 @@ namespace FemboyWatchdog
|
||||
{
|
||||
public partial class Toolbar : Form
|
||||
{
|
||||
private DateTime clockIn = DateTime.Now;
|
||||
|
||||
private FilterInfoCollection videoDevices;
|
||||
private VideoCaptureDevice videoDevice;
|
||||
private VideoCapabilities[] videoCapabilities;
|
||||
|
||||
private Timer labelBlinkTimer;
|
||||
private Timer ttsTimer;
|
||||
private Timer mousemvmtTimer;
|
||||
private int mousemvmtCount = 0;
|
||||
/* mouse movements come in as a stream, so we'll say a mouse movement is "over" by waiting
|
||||
a certain time with no movement */
|
||||
private Timer lastmousemvmtTimer;
|
||||
|
||||
private SpeechSynthesizer ss;
|
||||
|
||||
private SolidBrush brush = new SolidBrush(Color.Red);
|
||||
private Font font = new Font(FontFamily.GenericSansSerif, 24);
|
||||
|
||||
private GlobalHooks.LowLevelMouseProc _proc;
|
||||
private static IntPtr _hookID = IntPtr.Zero;
|
||||
|
||||
|
||||
public Toolbar()
|
||||
{
|
||||
_proc = OnMouseMessage;
|
||||
GlobalHooks.SetHook(_proc);
|
||||
InitializeComponent();
|
||||
|
||||
ss = new SpeechSynthesizer();
|
||||
@ -37,15 +51,65 @@ namespace FemboyWatchdog
|
||||
ttsTimer.Interval = 15000;
|
||||
labelBlinkTimer = new Timer();
|
||||
labelBlinkTimer.Interval = 1000;
|
||||
mousemvmtTimer = new Timer();
|
||||
mousemvmtTimer.Interval = 60000;
|
||||
mousemvmtTimer.Start();
|
||||
lastmousemvmtTimer = new Timer();
|
||||
lastmousemvmtTimer.Interval = 500;
|
||||
|
||||
// hook events
|
||||
vsp.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(vsp_NewFrame);
|
||||
ttsTimer.Tick += new EventHandler(ttsTimer_Tick);
|
||||
labelBlinkTimer.Tick += new EventHandler(labelBlinkTimer_Tick);
|
||||
mousemvmtTimer.Tick += new EventHandler(mousemoveTimer_Tick);
|
||||
lastmousemvmtTimer.Tick += new EventHandler(lastmousemvmtTimer_Tick);
|
||||
|
||||
OpenCamera();
|
||||
}
|
||||
|
||||
void lastmousemvmtTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
++mousemvmtCount;
|
||||
lastmousemvmtTimer.Stop();
|
||||
}
|
||||
|
||||
void mousemoveTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (mousemvmtCount < 5)
|
||||
{
|
||||
SoundPlayer snd = new SoundPlayer(@"media\beep.wav");
|
||||
snd.Play();
|
||||
DialogResult answer = MessageBox.Show(
|
||||
this,
|
||||
string.Format("WORKER: Your productivity ({0}) is below 5 mouse movements/minute. Are you sleeping?", mousemvmtCount),
|
||||
"EMPLOYEE ALERT",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Exclamation
|
||||
);
|
||||
if (answer == DialogResult.Yes)
|
||||
{
|
||||
MessageBox.Show(
|
||||
this,
|
||||
"Expect a formal termination letter from human resources soon.",
|
||||
"YOU'RE FIRED!",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information
|
||||
);
|
||||
}
|
||||
}
|
||||
mousemvmtCount = 0;
|
||||
}
|
||||
|
||||
private IntPtr OnMouseMessage(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
if (nCode >= 0 && (GlobalHooks.MouseMessages)wParam == GlobalHooks.MouseMessages.WM_MOUSEMOVE)
|
||||
{
|
||||
if (!lastmousemvmtTimer.Enabled)
|
||||
lastmousemvmtTimer.Start();
|
||||
}
|
||||
return GlobalHooks.CallNextHookEx(_hookID, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
private void OpenCamera()
|
||||
{
|
||||
try
|
||||
@ -57,14 +121,14 @@ namespace FemboyWatchdog
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Camera device not found! Get a webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(this, "Camera device not found! Get a webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Environment.Exit(-2);
|
||||
return;
|
||||
}
|
||||
videoCapabilities = videoDevice.VideoCapabilities;
|
||||
if (videoCapabilities.Length == 0)
|
||||
{
|
||||
MessageBox.Show("Camera does not support video capture! Get a better webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(this, "Camera does not support video capture! Get a better webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Environment.Exit(-3);
|
||||
return;
|
||||
}
|
||||
@ -77,7 +141,7 @@ namespace FemboyWatchdog
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show(err.ToString(), "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(this, err.ToString(), "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
}
|
||||
@ -143,6 +207,7 @@ namespace FemboyWatchdog
|
||||
Graphics g = Graphics.FromImage(image);
|
||||
// paint current time
|
||||
g.DrawString(now.ToString(), font, brush, new Point(5, 5));
|
||||
g.DrawString("Clock in time: " + clockIn.ToString(), font, brush, new Point(5, image.Height - font.Height - 5));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
BIN
FemboyWatchdog/media/beep.wav
Normal file
BIN
FemboyWatchdog/media/beep.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user