Windows Taste sperren

  • VB.NET

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von VB2008Lover.

    Windows Taste sperren

    Hi liebe Gemeinde,

    diese Thema gibt es schon ewig. Ich habe auch GOOGLE und die Sufu benutzt. Bloß habe ich nur etwas mit einem Registry-Eintrag machen gefunden.
    Oder, dass das Programm abfrägt, ob die Taste gedrückt ist und dann ESC drückt

    1. Frage : Wie kann man Win-R und Win-L so sperren, dass diese auch gesperrt sind, wenn mein Programm keinen Focus mehr hat


    2. Wie kann ich den Taskmanager sperren?


    3. Wie kann ich die Kompination Win-R + --> sperren (Windows + Tab)


    4. Und wie kann ich Alt+Tab sperren



    Diese Themen wird es alle schon geben, es tut mir leid, dass ich das nochmal poste. Als antwort reicht auch ein Link^^


    PS: Das gilt für die Fragen 1 + 2: Soll immer gehen (außer wenn Form nicht an ist)

    Danke schon mal im Voraus, dass ihr euch nochmal die Mühe macht

    PPS: Des mit Win-R und Win-L soll ja mit den sogenannten "HOCKS" gehen (hoffe das ist richtig geschrieben) nach dem Schließen soll die Taste aber wieder gehen

    VB.NET-Quellcode

    1. Option Explicit On
    2. Imports System.Runtime.InteropServices
    3. Public Class Form1
    4. Private Declare Sub keybb_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    5. Private Const KEYEVENTF_KEYUP = &H2
    6. Private Delegate Function HOOKPROCDelegate(ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As IntPtr
    7. ' dauerhafte Delegaten-Variable erzeugen
    8. Private HookProc As New HOOKPROCDelegate(AddressOf KeyboardHookProc)
    9. Private Declare Unicode Function GetModuleHandleW Lib "kernel32.dll" (ByVal lpModuleName As IntPtr) As IntPtr
    10. ' Die Funktion, um einen globalen Hook setzen zu können:
    11. Private Declare Unicode Function SetWindowsHookExW Lib "user32.dll" (ByVal idHook As Integer, ByVal lpfn As HOOKPROCDelegate, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
    12. ' Für das Löschen des Hooks wird diese Funktion verwendet:
    13. Private Declare Unicode Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hhk As IntPtr) As UInteger
    14. Private Declare Unicode Function CallNextHookEx Lib "user32.dll" (ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As IntPtr
    15. Private Const WM_KEYDOWN As Int32 = &H100 ' Konstante für WM_KEYDOWN
    16. Private Const WM_KEYUP As Int32 = &H101 ' Konstante für WM_KEYUP
    17. Private Const HC_ACTION As Integer = 0 ' Konstante für HC_ACTION
    18. Private Const WH_KEYBOARD_LL As Integer = 13 ' Konstante für WH_KEYBOARD_LL
    19. Public PrevWndProc As Integer
    20. Private mHandle As IntPtr
    21. <StructLayout(LayoutKind.Sequential)> Public Structure KBDLLHOOKSTRUCT
    22. Public vkCode As Keys
    23. Public scanCode, flags, time, dwExtraInfo As UInteger
    24. Public Sub New(ByVal key As Keys, ByVal scancod As UInteger, ByVal flagss As UInteger, ByVal zeit As UInteger, ByVal extra As UInteger)
    25. vkCode = key
    26. scanCode = scancod
    27. flags = flagss
    28. time = zeit
    29. dwExtraInfo = extra
    30. End Sub
    31. End Structure
    32. Public Property KeyHookEnable() As Boolean
    33. Get
    34. Return mHandle <> IntPtr.Zero
    35. End Get
    36. Set(ByVal value As Boolean)
    37. If KeyHookEnable = value Then Return
    38. If value Then
    39. mHandle = SetWindowsHookExW(WH_KEYBOARD_LL, HookProc, _
    40. GetModuleHandleW(IntPtr.Zero), 0)
    41. Else
    42. UnhookWindowsHookEx(mHandle)
    43. mHandle = IntPtr.Zero
    44. End If
    45. End Set
    46. End Property
    47. Private Function KeyboardHookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As IntPtr
    48. Dim fEatKeyStroke As Boolean
    49. If nCode = HC_ACTION Then
    50. Select Case lParam.vkCode
    51. Case Keys.Shift
    52. fEatKeyStroke = True
    53. Case Keys.Alt
    54. fEatKeyStroke = True
    55. Case Keys.Home
    56. fEatKeyStroke = True
    57. Case Keys.Enter
    58. fEatKeyStroke = True
    59. Case Keys.Tab
    60. fEatKeyStroke = True
    61. Case Keys.End
    62. fEatKeyStroke = True
    63. Case Keys.Escape
    64. fEatKeyStroke = True
    65. Case Keys.LWin
    66. fEatKeyStroke = True
    67. Case Keys.RWin
    68. fEatKeyStroke = True
    69. Case Keys.Delete
    70. fEatKeyStroke = True
    71. End Select
    72. If fEatKeyStroke Then
    73. Return New IntPtr(1)
    74. Exit Function
    75. End If
    76. Return CallNextHookEx(mHandle, nCode, wParam, lParam)
    77. End If
    78. End Function
    79. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    80. ' Hook einschalten:
    81. KeyHookEnable = True
    82. Dim oRegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
    83. oRegKey.SetValue(My.Application.Info.AssemblyName, System.Windows.Forms.Application.ExecutablePath)
    84. End Sub
    85. Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    86. ' WICHTIG! Hook ausschalten beim Beenden nicht vergessen!!!
    87. KeyHookEnable = False
    88. End Sub


    die probleme hatte ich auch des sperrt alles was du willst auser den Taskmanager. Diuesen code brauch ich au noch

    VB.NET-Quellcode

    1. Dim proc As System.Diagnostics.Process
    2. Dim pList() As Process
    3. pList = Process.GetProcessesByName("taskmgr")
    4. For Each proc In pList
    5. proc.Kill()
    6. Next

    in einen timer rein und wenn der taskmgr startet beendet er sofort

    für die windows tasten habe ich mir eine nicht ganz saubere metode ausgedacht: die explorer.exe killen, mit einer .bat-datei

    jakob1410 schrieb:

    VB.NET-Quellcode

    1. Dim proc As System.Diagnostics.Process
    2. Dim pList() As Process
    3. pList = Process.GetProcessesByName("taskmgr")
    4. For Each proc In pList
    5. proc.Kill()
    6. Next

    in einen timer rein und wenn der taskmgr startet beendet er sofort

    für die windows tasten habe ich mir eine nicht ganz saubere metode ausgedacht: die explorer.exe killen, mit einer .bat-datei


    also das geht bei mir net