Disable CTRL+ESC

disable the startmenu from Showing up

Page 1 of 1

13 Replies - 5717 Views - Last Post: 13 November 2009 - 02:29 PM Rate Topic: -----

#1 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Disable CTRL+ESC

Posted 08 November 2009 - 11:16 PM

Hi Guys,

How can i Disable CTRL+ESC using VB.NET? I want to disable the Startmenu from showing up.

Regards,
Is This A Good Question/Topic? 0
  • +

Replies To: Disable CTRL+ESC

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Disable CTRL+ESC

Posted 08 November 2009 - 11:33 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 1
  • +
  • -

#3 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Re: Disable CTRL+ESC

Posted 08 November 2009 - 11:50 PM

Hi,
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

Was This Post Helpful? 0
  • +
  • -

#4 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Re: Disable CTRL+ESC

Posted 09 November 2009 - 04:02 AM

Sorry for this... but, please.. could someone translate this to VB.net... - i'm fairly new with vb2008.

Link Here

sorry for being sort of demanding...

Regards,
Was This Post Helpful? 0
  • +
  • -

#5 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

Re: Disable CTRL+ESC

Posted 09 November 2009 - 04:15 AM

ur code is called when on keydown on your own form and then tests to see if the keys where Keys.LWin or Keys.RWin or a combo of Keys.ControlKey and Keys.Escape. are you sure when u hit the ctrl-esc your form was in focus?
Was This Post Helpful? 0
  • +
  • -

#6 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Disable CTRL+ESC

Posted 09 November 2009 - 06:38 AM

edit (never mind, made a mistake)

This post has been edited by crepitus: 09 November 2009 - 06:39 AM

Was This Post Helpful? 0
  • +
  • -

#7 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Re: Disable CTRL+ESC

Posted 09 November 2009 - 11:26 PM

View Postolibenu, on 9 Nov, 2009 - 03:15 AM, said:

ur code is called when on keydown on your own form and then tests to see if the keys where Keys.LWin or Keys.RWin or a combo of Keys.ControlKey and Keys.Escape. are you sure when u hit the ctrl-esc your form was in focus?


Hi there.. yep.. my i have the focus on my form
Was This Post Helpful? 0
  • +
  • -

#8 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Disable CTRL+ESC

Posted 10 November 2009 - 10:03 AM

Why not just get your program to run a Taskkill on windows explorer if you dont want a start menu to come up?
Was This Post Helpful? 0
  • +
  • -

#9 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Re: Disable CTRL+ESC

Posted 10 November 2009 - 06:50 PM

View PostJack Eagles1, on 10 Nov, 2009 - 09:03 AM, said:

Why not just get your program to run a Taskkill on windows explorer if you dont want a start menu to come up?


Hi Jack.,

thanks for your reply.. sorry for this question.. but is this safe? i mean, overtime would it mess the system?

Regards,
Was This Post Helpful? 0
  • +
  • -

#10 LeisureProgrammer  Icon User is offline

  • N00by VB.NET Developer
  • member icon

Reputation: 110
  • View blog
  • Posts: 588
  • Joined: 06-September 09

Re: Disable CTRL+ESC

Posted 10 November 2009 - 07:29 PM

I end explorer.exe all the time - I don't know how that could be bad for the system.
Was This Post Helpful? 0
  • +
  • -

#12 Searock  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 259
  • Joined: 15-September 09

Re: Disable CTRL+ESC

Posted 11 November 2009 - 10:33 AM

If you go on killing your explorer.exe you will end up messing with your system.
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

Was This Post Helpful? 1
  • +
  • -

#13 octane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 04-November 09

Re: Disable CTRL+ESC

Posted 11 November 2009 - 06:39 PM

View PostSearock, on 11 Nov, 2009 - 09:33 AM, said:

If you go on killing your explorer.exe you will end up messing with your system.
I have tried it out and it corrupts the explorer.exe file


whoa!!! i thought so. :D
Was This Post Helpful? 0
  • +
  • -

#14 Searock  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 259
  • Joined: 15-September 09

Re: Disable CTRL+ESC

Posted 12 November 2009 - 11:31 PM

Finally after finding many vb6 solutions luckily I got hold of one of the .Net Solution.
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

Was This Post Helpful? 0
  • +
  • -

#15 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Disable CTRL+ESC

Posted 13 November 2009 - 02:29 PM

Okay, then why not just make a timer in your app which has in the tick event:

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1