• 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.
  • Posts

    • I wasn't implying people should be forced to use a single launcher. I prefer user choice. If Windows includes a decent game launcher, great, people might choose to use it if they want to. If it sucks, no one will use it. I would be completely against anyone being forced in that direction, just like I am against being forced to use 3rd party launchers if I choose to use Steam.
    • Sounds good, but that'd require Microsoft to develop and API of some sort and then get all the developers to support it... but everyone knows that while others will support Microsoft, Microsoft won't support itself and will kill off the feature... again. Microsoft has tried this trick in Windows 9x era, they tried it with the games library in Vista, they tried a big push for Games for Windows Live, and then again in Windows 8 with the WPA apps via their mobile/windows phone eco system. Now they're trying it again, and it's lets not forget that this isn't a push to make PC gaming better. It's not. To do that they need to provide at least the same level of quality and feature set of Steam, otherwise why else are gamers going to not use Steam. Right now Xbox app and everything Microsoft centric around the PC gaming front is exclusively for their new Xbox brand push to make everything an Xbox. Your Toaster, your cat, your PC, your VR headset, everything is a Xbox and that'll last for this generation of Xbox now probably. Then, like Microsoft always has done and will do, they'll drop it like a hot potato and everyone will be left crying. Point in case, bringing Xbox games to the ROG handheld, their entire point of this... They're marketing it as if it's an Xbox console in a handheld, yet, it's not. There are going to be Xbox gamers who think, they'll be able to pickup their Xbox one games and play them on a handheld like Nintendo and Steam Deck users... except they're going to quickly find out that their Xbox game library is almost entirely missing or games they've already purchased on the Xbox need to be purchased again on the 'this is an Xbox' handheld.
    • man i remember hearing about new icons years ago and we still are at this......
    • That's entirely speculation. If he wants these on the road, I would assume (and hope) that he's tested the crap out of these things in real world scenario simulations until he (and any government regulators) are 100% convinced that they are as safe as a human driver before letting them on the streets of a real city. You don't test an automated ton of steel and aluminum with a big engine capable of going up to 200 mph by sticking it a public street with a human behind the wheel "just in case" and hoping for the best.
  • Recent Achievements

    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • One Month Later
      GoForma earned a badge
      One Month Later
    • Week One Done
      GoForma earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      637
    2. 2
      Michael Scrip
      224
    3. 3
      ATLien_0
      219
    4. 4
      +FloatingFatMan
      142
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!