• 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

    • Underwhelming update. Same as 12,13,14,15. Then M3E ain't showing up until Q3
    • Smart Launcher seems a better option right now.
    • Mistral AI's new 'Magistral' models bring traceable, faster AI reasoning by Paul Hill One of Europe’s leading AI companies, Mistral, has announced the availability of its Magistral reasoning model. It comes in two versions: there is the open-source Magistral Small (24B parameters) and the enterprise-focused Magistral Medium. Magistral has been designed to better handle domain-specific tasks such as law, finance, and engineering. It shows users the model’s thought processes so that it’s more transparent, and it supports multilingual reasoning to perform better when tasked with answering non-English queries. Key features and performance Mistral compared its new models against DeepSeek R1 in various benchmarks. Ones that stood out were its results on AIME2024, which assesses reasoning capabilities. Magistral Medium scored 73.6% (90% with majority voting @64) while Small scored 70.7% (83.3% respectively). If you’ve used DeepSeek R1, you’ll have seen it thinking before answering. Magistral now does this too and can do it across multiple languages, including English, French, Spanish, German, Italian, Arabic, Russian, and Simplified Chinese. Interestingly, there’s also a Flash Answers mode that speeds up the thinking for 10x faster responses compared to competitors. Real-world applications and availability Thanks to the expertise Magistral has been trained on, organizations across multiple fields, including legal research, financial forecasting, and regulated industries, may be able to turn to Magistral for more reliable answers. Its traceable reasoning also makes it ideal in regulated fields for compliance and auditability. Magistral Small, the open-source model, is available under an Apache 2.0 license via Hugging Face. Magistral Medium is accessible through Mistral's Le Chat and via API on La Plateforme. It’ll also be arriving soon on Amazon SageMaker, IBM WatsonX, Azure AI, and Google Cloud Marketplace. The easiest way for readers to try it out is on Mistral's Le Chat platform; just head to chat.mistral.ai to get started. Source: Mistral
    • Didn't know this thanks, useful.
    • I had to check your comment history to see what you were referring to here. One word... Wow! I asked him myself. LOL
  • Recent Achievements

    • Week One Done
      elsa777 earned a badge
      Week One Done
    • One Month Later
      elsa777 earned a badge
      One Month Later
    • First Post
      K Dorman earned a badge
      First Post
    • Reacting Well
      rshit earned a badge
      Reacting Well
    • Reacting Well
      Alan- earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      544
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      207
    4. 4
      +Edouard
      201
    5. 5
      snowy owl
      139
  • Tell a friend

    Love Neowin? Tell a friend!