• 0

(VB.net) Disabling keys


Question

i would like to know how to disable some keys on the keyboard in vb2005.

I am making a gaming program where u chose ur game from a list and then it runs it.

but the user must not be able to get onto the OS.

I know that it is almost impossible to stop ctrl, alt delete, but i would like to know how to disable

alt, ctrl, windows key, and F4.

thanks for any help

Link to comment
https://www.neowin.net/forum/topic/562480-vbnet-disabling-keys/
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi

You need to have the following function in your code so that your application can trap the keypresses and make them do what you want them to do rather than the operating system default:

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean

		Select Case (keyData)
			Case Keys.Control
				MessageBox.Show("Controlpressed")
			Case Keys.Alt Or Keys.F4
				MessageBox.Show("Altressed")
		End Select
		Return MyBase.ProcessDialogKey(keyData)
	End Function

You will of course need to add more definitions for your own custom purposes.

This has been put together quickly, and may not be so accurate. I'm more of a C# developer than VB.NET

  • 0

i remember doing this ages ago in VB6 in an attempt to help someone prevent people using the Windows+U combo to bypass their custom login program, code worked too but they didn't wanna use it (blocked windows from being used until logged in)

  • 0
  darthblader said:
ah right ok. i have it running here for all my buttons that i need but they continue to run after the messagebox

how do u get it to not close down on some of the occassions lol

I put Return True after the message boxes:

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean

		Select Case (keyData)
			Case Keys.Control
				MessageBox.Show("Controlpressed")
				Return True
			Case Keys.Alt Or Keys.F4
				MessageBox.Show("Altressed")
				Return True
		End Select
		Return MyBase.ProcessDialogKey(keyData)
	End Function

which seemed to work here

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.