• 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

    • Can you point out any such "nonsensical opinion" in the article? Is it the fact that Waymo is ahead of Tesla when it comes to "robotaxis," at least in terms of real-world usage? The only thing I see that comes close to an "opinion" is the question I asked about vandalism, given that Elon Musk and Tesla are not super popular right now, and we've already seen what an angry mob needlessly do a self-driving car. As for the title of the article, we all know about Musk's track record with promises, even huge Tesla fanboys cannot deny that; so I decided to go with a title that nods to the fact that this is not the first time we're hearing of Tesla robotaxis launching "soon."
    • Ohh can canopees always shed information on nonsensical alien latin?
    • It is supervised but yes, the car is all the driving and it does it excellent.
    • Save $90 on a Microsoft Office 2024 Home & Business for Mac or PC license by Steven Parker Today's highlighted deal comes via Neowin Deals store, where you can save 36% on Microsoft Office 2024 Home & Business for Mac or PC Lifetime License. (buying link below) The essentials to get it all done. Microsoft Office 2024 Home is the latest version of Microsoft’s renowned productivity suite, which includes essential applications like Word, Excel, PowerPoint, and OneNote. This version is specifically designed for individuals and families seeking reliable tools for various home tasks, including document creation, spreadsheet management, presentation design, and note-taking. Office Home 2024 is for students and families who want classic Office apps on their Mac or PC. A one-time purchase installed on 1 PC or Mac for use at home or school. Lifetime license for MS Word, Excel, PowerPoint, & OneNote One-time purchase installed on 1 Windows PC for use at home or work Instant Delivery & Download – access your software license keys and download links instantly Free customer service – only the best support! Microsoft Office 2024 Home for PC or Mac includes: Microsoft Office Word Microsoft Office Excel Microsoft Office PowerPoint Microsoft Office OneNote No faffing about with subscriptions, just classic apps that don't expire.Good to Know ONE-TIME PURCHASE INSTALLED ON 1 DEVICE Redemption deadline: redeem your code within 30 days of purchase Access options: desktop Full versions No subscriptions – no monthly/annual fees Version: 2024 Updates included A lifetime subscription to Microsoft Office Home 2024 normally costs $249.99, but this deal can be yours for just $159.97, that's a saving of $90. For full terms, specifications, and license info, click the link below. Get Microsoft Office 2024 for just $159.97 (36% off MSRP: $249.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
  • Recent Achievements

    • Apprentice
      Cole Multipass went up a rank
      Apprentice
    • Posting Machine
      David Uzondu earned a badge
      Posting Machine
    • One Month Later
      Stokenking earned a badge
      One Month Later
    • One Month Later
      Kevin Jones earned a badge
      One Month Later
    • Week One Done
      Kevin Jones earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      547
    2. 2
      ATLien_0
      269
    3. 3
      +Edouard
      194
    4. 4
      +FloatingFatMan
      181
    5. 5
      snowy owl
      137
  • Tell a friend

    Love Neowin? Tell a friend!