Disable CTRL+ESCdisable the startmenu from Showing up
Page 1 of 1
13 Replies - 4752 Views - Last Post: 13 November 2009 - 02:29 PM
#1
Disable CTRL+ESC
Posted 08 November 2009 - 11:16 PM
How can i Disable CTRL+ESC using VB.NET? I want to disable the Startmenu from showing up.
Regards,
Replies To: Disable CTRL+ESC
#2
Re: Disable CTRL+ESC
Posted 08 November 2009 - 11:33 PM
Post your code like this:
Thanks.
#3
Re: Disable CTRL+ESC
Posted 08 November 2009 - 11:50 PM
Sorry.., anyways, here's the code. i got it from RodgerB. this code was able to disable Windows keys.
i just added the VK_CONTOL & VK_ESCAPE in the declaration. and added this
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1 Private Const KEYEVENTF_KEYUP As Long = &H2 Private Const VK_LWIN As Byte = &H5B Private Const VK_CONTROL As Byte = &H11 Private Const VK_ESCAPE As Byte = &H1B Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _ ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.LWin Or e.KeyCode = Keys.RWin Then keybd_event(Keys.Zoom, 0, KEYEVENTF_EXTENDEDKEY, 0) If e.KeyCode = Keys.ControlKey And e.Modifiers = Keys.Escape Then keybd_event(Keys.Zoom, 0, KEYEVENTF_EXTENDEDKEY, 0) End Sub
but when my form loads (form is maximized covering the whole screen) and i pressed CTRL+ESC, the StartMenu still shows up.
Regards,
This post has been edited by octane: 08 November 2009 - 11:52 PM
#5
Re: Disable CTRL+ESC
Posted 09 November 2009 - 04:15 AM
#6
Re: Disable CTRL+ESC
Posted 09 November 2009 - 06:38 AM
This post has been edited by crepitus: 09 November 2009 - 06:39 AM
#7
Re: Disable CTRL+ESC
Posted 09 November 2009 - 11:26 PM
olibenu, on 9 Nov, 2009 - 03:15 AM, said:
Hi there.. yep.. my i have the focus on my form
#8
Re: Disable CTRL+ESC
Posted 10 November 2009 - 10:03 AM
#9
Re: Disable CTRL+ESC
Posted 10 November 2009 - 06:50 PM
#10
Re: Disable CTRL+ESC
Posted 10 November 2009 - 07:29 PM
#12
Re: Disable CTRL+ESC
Posted 11 November 2009 - 10:33 AM
I have tried it out and it corrupts the explorer.exe file
This post has been edited by Searock: 11 November 2009 - 10:33 AM
#13
Re: Disable CTRL+ESC
Posted 11 November 2009 - 06:39 PM
#14
Re: Disable CTRL+ESC
Posted 12 November 2009 - 11:31 PM
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class Form1
'Structure contain information about low-level keyboard input event
Private Structure KBDLLHOOKSTRUCT
Public key As Keys
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public extra As IntPtr
End Structure
'System level functions to be used for hook and unhook keyboard input
Private Delegate Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SetWindowsHookEx(ByVal id As Integer, ByVal callback As LowLevelKeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function UnhookWindowsHookEx(ByVal hook As IntPtr) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function CallNextHookEx(ByVal hook As IntPtr, ByVal nCode As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function GetModuleHandle(ByVal name As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function GetAsyncKeyState(ByVal key As Keys) As Short
End Function
'Declaring Global objects
Private ptrHook As IntPtr
Private objKeyboardProcess As LowLevelKeyboardProc
Public Sub New()
Dim objCurrentModule As ProcessModule = Process.GetCurrentProcess().MainModule
'Get Current Module
objKeyboardProcess = New LowLevelKeyboardProc(AddressOf captureKey)
'Assign callback function each time keyboard process
ptrHook = SetWindowsHookEx(13, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0)
'Setting Hook of Keyboard Process for current module
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Function captureKey(ByVal nCode As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
If nCode >= 0 Then
Dim objKeyInfo As KBDLLHOOKSTRUCT = DirectCast(Marshal.PtrToStructure(lp, GetType(KBDLLHOOKSTRUCT)), KBDLLHOOKSTRUCT)
If objKeyInfo.key = Keys.RWin OrElse objKeyInfo.key = Keys.LWin Then
' Disabling Windows keys
Return CType(1, IntPtr)
End If
If objKeyInfo.key = Keys.ControlKey OrElse objKeyInfo.key = Keys.Escape Then
' Disabling Ctrl + Esc keys
Return CType(1, IntPtr)
End If
End If
Return CallNextHookEx(ptrHook, nCode, wp, lp)
End Function
End Class
and replace your dispose method with
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso (components IsNot Nothing) Then components.Dispose() End If If ptrHook <> IntPtr.Zero Then UnhookWindowsHookEx(ptrHook) ptrHook = IntPtr.Zero End If MyBase.Dispose(disposing) End Sub
Code taken from http://geekswithblogs.net and converted from C# to vb.net from http://www.developer...t/csharp-to-vb/.
and don't forget to handle Alt + F4 key combination.
This post has been edited by Searock: 13 November 2009 - 05:47 PM
#15
Re: Disable CTRL+ESC
Posted 13 November 2009 - 02:29 PM
Me.TopMost = True Me.BringToFront Me.WindowState = FormWindowState.Maximized
And then enable it or disable it with a timer. This will solve all your problems in one go. give it a try.
|
|

New Topic/Question
Reply




MultiQuote





|