How to record actions in a compact environment?

I am working on a Windows Mobile project using a compact structure.

One thing I have to do is register when users perform actions, this can mean any action from clicking a button to using a barcode scanner. The time at which it also occurred should be recorded.

My plan is to override all controls by including the built-in logging functions in them, but this may not be the right way to do this, it seems to be a very tedious thing.

Is there a better way?

+5
source share
3 answers
+2

, "". , API () QASetWindowsJournalHook. , , , . Codeproject .

SetWindowsHook WH_JOURNALRECORD . , , "", , , ( 10 ).

P/Invoke, pwinuser.h, :

[StructLayout(LayoutKind.Sequential)]
public struct JournalHookStruct
{

  public int message { get; set; }
  public int paramL { get; set; }
  public int paramH { get; set; }
  public int time { get; set; }
  public IntPtr hwnd { get; set; }
}

internal enum HookType
{
  JournalRecord = 0,
  JournalPlayback = 1,
  KeyboardLowLevel = 20
}

internal enum HookCode
{
  Action = 0,
  GetNext = 1,
  Skip = 2,
  NoRemove = 3,
  SystemModalOn = 4,
  SystemModalOff = 5
}

public const int HC_ACTION = 0;
public const int LLKHF_EXTENDED = 0x1;
public const int LLKHF_INJECTED = 0x10;
public const int LLKHF_ALTDOWN = 0x20;
public const int LLKHF_UP = 0x80;
public const int VK_TAB = 0x9;
public const int VK_CONTROL = 0x11;
public const int VK_ESCAPE = 0x1B;
public const int VK_DELETE = 0x2E;


[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(HookType idHook, HookProc lpfn, IntPtr hMod, int 

[DllImport("coredll.dll", SetLastError = true)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);

[DllImport("coredll.dll", SetLastError = true)]
public static extern int CallNextHookEx(IntPtr hhk, HookCode nCode, IntPtr wParam, IntPtr 

[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr QASetWindowsJournalHook(HookType nFilterType, HookProc pfnFilterProc, ref JournalHookStruct pfnEventMsg);
+1

?

#if PocketPC
private static string _appPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
#else
private static string _appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Application.CompanyName);
#endif
public const int KILOBYTE = 1024;
public static string ErrorFile { get { return _appPath + @"\error.log"; } }

public static void Log(string message)
{
  if (String.IsNullOrEmpty(message)) return;
  using (FileStream stream = File.Open(ErrorFile, FileMode.Append, FileAccess.Write))
  {
    using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8, KILOBYTE))
    {
      sw.WriteLine(string.Format("{0:MM/dd/yyyy HH:mm:ss} - {1}", DateTime.Now, message));
    }
  }
}

, , . .

, .

#if , Windows.

+1

All Articles