Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I have a VB.net program that runs for 24 hours and scans a directory for files then displays the results in a RichTextBox window when they are present.
The user presses a key on the keyboard once the contents are viewed and clears the RTB and deletes the file.

My "program" will occasionally lose focus and the keyboard input is redirected away from the main Program.

A mouse is not connected so the user is not clicking on another program or portion of the screen.

This program restarts automatically at 4am daily and it's hit or miss if the keyboard stays connected to my program.

This application is the only program running on this computer.
I've checked for windows scheduled tasks, there are some google updates and a few other update applications running. Short of deleting them I'd like find a way to regain focus of the keyboard.

Cheers,
KB

What I have tried:

I have this at program startup and during the file scanning procedure with no results.
  Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
  Me.WindowState = FormWindowState.Maximized
  Me.TopMost = True


If I click on the program the keyboard will continue to work.
Posted
Updated 21-Mar-22 5:31am

Have you tried handling the Form.Deactivate Event (System.Windows.Forms) | Microsoft Docs[^]?
You could then set the focus to your app again. I haven't tried it - if it fails it might be hard to do anything else with the computer short of pulling the mains plug - but this seems to explain the process: Bring an application to front with CSharp – Shatter-Box[^] - it's C#, but you should be able to get it working in VB.
 
Share this answer
 
I found the answer Me.Activate()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900