birdyb
Goto Top

Powershell: Mausklicks zählen

Hallo zusammen,

für eine Auswertung zu bestimmten Softwareprozessen muss ich für einige Aktionen zählen, wieviele Mausklicks ich dafür benötige.
Leider kann ich die zwei Freeware-Tools, die ich im Internet gefunden habe nicht nutzen und dachte mir nun, ich könnte vielleicht per PS eine kleine App bauen, die mitzählt, wie oft ich klicke.
Irgendwie finde ich aber keinen Ansatz, wie ich Mausklicks registrieren / zählen kann.
Hat jemand von euch vielleicht eine Idee?

Vielen Dank und beste Grüße

Content-Key: 615630

Url: https://administrator.de/contentid/615630

Printed on: April 19, 2024 at 05:04 o'clock

Member: tech-flare
Solution tech-flare Oct 23, 2020 updated at 12:40:30 (UTC)
Goto Top
Dafür eignet sich AutoIt.

Erstelle damit ein kleines Programm, welches die Klicks in eine Logdatei schreibt

Du kannst damit eine EXE erstellen und diese auf dem PC ausführen.. installiert werde muss dafür nichts
Member: colinardo
Solution colinardo Oct 23, 2020 updated at 13:09:21 (UTC)
Goto Top
Servus Birdy,
auch mit der PS kein großartiges Problem, Globaler Mouse Hook angelegt und schon wartet die PS auf sämtliche Klicks:
Add-Type -TypeDefinition '  
using System;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ClickCounter {
  public static class Prog {
    private const int WH_MOUSE_LL = 14;
    private const int WM_LBUTTONDOWN = 0x201;
    private const int WM_RBUTTONDOWN = 0x204;
    private const int WM_MBUTTONDOWN = 0x207;

    private static HookProc hookProc = HookCallback;
    private static IntPtr hookId = IntPtr.Zero;
    private static int keyCode = 0;

    [DllImport("user32.dll")]  
    private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll")]  
    private static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll")]  
    private static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("kernel32.dll")]  
    private static extern IntPtr GetModuleHandle(string lpModuleName);

    public static int WaitForClick() {
      hookId = SetHook(hookProc);
      Application.Run();
      UnhookWindowsHookEx(hookId);
      return keyCode;
    }

    private static IntPtr SetHook(HookProc hookProc) {
      IntPtr moduleHandle = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
      return SetWindowsHookEx(WH_MOUSE_LL, hookProc, moduleHandle, 0);
    }

    private delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);

    private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
      if (nCode >= 0 && (wParam == (IntPtr)WM_LBUTTONDOWN || wParam == (IntPtr)WM_RBUTTONDOWN || wParam == (IntPtr)WM_MBUTTONDOWN)) {
        keyCode = Marshal.ReadInt32(lParam);
        Application.Exit();
      }
      return CallNextHookEx(hookId, nCode, wParam, lParam);
    }
  }
}
' -ReferencedAssemblies System.Windows.Forms  

$cnt = 0
while ($true) {
    [void][ClickCounter.Prog]::WaitForClick()
    $cnt++
    "Clicks: $cnt"  
}
Grüße Uwe
Member: BirdyB
BirdyB Oct 23, 2020 at 13:34:15 (UTC)
Goto Top
Uwe, du bist mal wieder meine Rettung...
Schick mir doch bitte nochmal den Link für die Bier-/Kaffee- oder sonstwas-Spenden face-wink

Vielen Dank!
Member: colinardo
colinardo Oct 23, 2020 updated at 13:42:01 (UTC)
Goto Top
Zitat von @BirdyB:

Uwe, du bist mal wieder meine Rettung...
Schick mir doch bitte nochmal den Link für die Bier-/Kaffee- oder sonstwas-Spenden face-wink
Du hast ne PN face-smile.

Grüße Uwe