vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Blitzschnelles Erstellen von grafischen Diagrammen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Mouse-Keyboard Hooks und Verzögerung 
Autor: STSC
Datum: 31.03.05 12:42

Hallo,

ich versuche gerade die User Inactivity festzustellen und dachte das beste wäre das mit Hooks zu machen, jedoch kommt es dann immer wieder vor, dass die Maus furchtbar langsam wird. Was mache ich denn falsch? Hier ist der Code:

Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Drawing
Imports System.Threading
Imports PVRScheduler.SchedulerData
 
Public Class clsHookMonitor
 
    Public Declare Function UnhookWindowsHookEx Lib "user32" _
      (ByVal hHook As Integer) As Integer
 
    Public Declare Function SetWindowsHookEx Lib "user32" _
      Alias "SetWindowsHookExA" (ByVal idHook As Integer, _
      ByVal lpfn As HookDelegate, ByVal hmod As IntPtr, _
      ByVal dwThreadId As Integer) As Integer
 
    Private Declare Function GetAsyncKeyState Lib "user32" _
      (ByVal vKey As Integer) As Integer
 
    Private Declare Function CallNextHookEx Lib "user32" _
      (ByVal hHook As Integer, ByVal nCode As Integer, _
      ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
 
 
    Public Delegate Function HookDelegate(ByVal nCode As Integer, _
        ByVal wParam As IntPtr, ByRef lParam As IntPtr) As Integer
 
    Private Const WH_KEYBOARD_LL As Integer = 13
    Private Const WH_MOUSE_LL As Integer = 14
 
    Private SchedulerIni As clsInit = clsInit.Instance
 
    Public KeyboardHandle As Integer
    Public MouseHandle As Integer
    Private c_LastInput As Date
 
    Public Function KeyboardCallback(ByVal nCode As Integer, _
      ByVal wParam As IntPtr, _
      ByRef lParam As IntPtr) As Integer
 
        If nCode >= 0 Then
            Reset()
        End If
 
        Return CallNextHookEx(KeyboardHandle, _
          nCode, wParam, lParam)
 
    End Function
 
    <MarshalAs(UnmanagedType.FunctionPtr)> _
    Private KeyboardHandler As HookDelegate
 
    Public Sub HookKeyboard()
        If KeyboardHandle = 0 Then
            KeyboardHandler = New HookDelegate(AddressOf KeyboardCallback)
 
            KeyboardHandle = SetWindowsHookEx( _
              WH_KEYBOARD_LL, KeyboardHandler, _
              Marshal.GetHINSTANCE( _
              [Assembly].GetExecutingAssembly.GetModules()(0)), 0)
 
            If KeyboardHandle = 0 Then
                SchedulerIni.LogWrite("Keyboard hook failed: " & _
                  Err.LastDllError)
            End If
        End If
    End Sub
 
    Public Sub UnhookKeyboard()
        If (KeyboardHandle <> 0) Then
            If UnhookWindowsHookEx(KeyboardHandle) Then
                SchedulerIni.LogWrite("Keyboard unhook failed: " & _
                  Err.LastDllError)
                KeyboardHandle = 0
                KeyboardHandler = Nothing
            End If
        End If
    End Sub
 
    <MarshalAs(UnmanagedType.FunctionPtr)> _
    Private MouseHandler As HookDelegate
 
 
    Public Function MouseCallback(ByVal nCode As Integer, ByVal wParam As _
      IntPtr, _
  ByRef lParam As IntPtr) As Integer
 
        If nCode >= 0 Then
            Reset()
        End If
 
        Return CallNextHookEx(MouseHandle, _
          nCode, wParam, lParam)
 
    End Function
 
    Public Sub HookMouse()
        If MouseHandle = 0 Then
            MouseHandler = New HookDelegate(AddressOf MouseCallback)
 
            MouseHandle = SetWindowsHookEx( _
              WH_MOUSE_LL, MouseHandler, _
              Marshal.GetHINSTANCE( _
              [Assembly].GetExecutingAssembly.GetModules()(0)), 0)
 
            If MouseHandle = 0 Then
                SchedulerIni.LogWrite("Mouse hook failed: " & Err.LastDllError)
            End If
        End If
    End Sub
 
    Public Sub UnhookMouse()
        If (MouseHandle <> 0) Then
            If UnhookWindowsHookEx(MouseHandle) Then
                SchedulerIni.LogWrite("Mouse unhook failed: " & _
                  Err.LastDllError)
                MouseHandle = 0
                MouseHandler = Nothing
            End If
        End If
    End Sub
 
    Public Sub New()
    End Sub
    Public Sub Reset()
        LastInput = Now
    End Sub
 
    Property LastInput() As Date
        Get
            Return c_LastInput
        End Get
        Set(ByVal Value As Date)
            c_LastInput = Value
        End Set
    End Property
 
End Class
Danke!
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Mouse-Keyboard Hooks und Verzögerung2.272STSC31.03.05 12:42

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel