Question Use Ctrl + T to globaly open a specific form?

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
Hey, I am making a somewhat relaxing non-linear game based around an evolving operating system (not a real one) called ShiftOS.

Just so you understand the general gist of how the game works here is some info which you are free to skip:

"A mysterious hacker named "DevX" hijacks your computer with the intention of using it as a remote test bed for his experimental operating system. After unwillingly having your hard drive wiped you become an involuntary beta tester for ShiftOS.

DevX's goal is to make ShiftOS the most intelligent operating system in the world that shifts and evolves as people use it. Play games, design images and make calculations within ShiftOS to earn CP (code points) which you can spend on new programs, GUI improvements and evolve other various features of ShiftOS.

Beware though, As ShiftOS evolves it will eventually begin to write it's own code as it learns from your human interactions causing it to EnCt264f03d9ac58ac9910224c508fde486b21263576164f03d9ac58ac9910224c5087JRivCDbbAH
AVHd+gFILzHawY/cp++5vm9fLB1LEnEvSLfJkRrm8svmA5LxMlwsx7FKcSkOYe4I=IwEmS << encrypted by ShiftOS."


Anyway in the early stages of the game the operating system is practically text based and involves typing a lot of commands to perform tasks. I've got the virtual terminal working nicely with reading and outputting the commands however I have am having a lot of difficulty with a certain critical early game ability.

The terminal is full screen and my plan is to make it pop up (unhide) when ctrl + t is pressed and disappear (hide) when ctrl + t is pressed. So far I have nailed the hiding of the terminal with the following code:

Private Sub txtterm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtterm.KeyDown
If e.KeyCode = Keys.T AndAlso e.Control Then
Me.Hide()
End If
End Sub

The issue however is the showing of the terminal. Obviously I can show the terminal with Terminal.show but where exactly can I put that code?

The user might be on the ShiftOS Desktop, in a ShiftOS drawing application or goodness knows where... So I really need to set some kind of global hotkey or something that no matter what form I am in it detects ctrl + t and shows the Terminal and brings it into focus.

How can I do this?
 
Last edited:
You have two options:

1. Handle the KeyPress event of every form in your app. This is not an onerous as it sounds though. What you can do is create a base class that inherits Form and adds that functionality, then all your other forms can inherit that class instead of Form. You then only actually need to handle the KeyPress event, or preferably override the OnKeyPress method, in one place and it will work for every single form.

2. Create a true hotkey, i.e. use the RegisterHotKey API to register with the OS (the real OS). When you receive the notification, you can check that your app has focus and, if so, do what needs to be done.

I'd go with the first option.
 
Back
Top