| | |
Couple of questions
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2006
Posts: 117
Reputation:
Solved Threads: 0
I just want to catch a single key press, and make it do something. I want it so when a key is pressed, nothing is displayed on the screen (as console.readline() does...)
I just want a silent (non noticable) action to take place when a key is pressed. Something like this;
I just want to press the key, and not have to worry about pressing return.
I just want a silent (non noticable) action to take place when a key is pressed. Something like this;
•
•
•
•
Please press 'k' to do this
Please press "x" to exit the program
I just want to press the key, and not have to worry about pressing return.
well why dont you try the keyPress event.. and is it a windows application or a console application.. if you are using windows then try using the forms-> keypress event :-|
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
One is as though nothing is a miracle.
The other is as if everything is.
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
arjunsasidharan is right.
On your form properties set the KeyPreview to true. Then use code simular to this:
On your form properties set the KeyPreview to true. Then use code simular to this:
VB.NET Syntax (Toggle Plain Text)
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress Select Case e.KeyChar Case "k", "K" MessageBox.Show("k was pressed") Case "x", "X" Me.Close() End Select End Sub
Last edited by waynespangler; Mar 3rd, 2007 at 9:45 am.
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
Then try this:
Hope this is what you want.
VB.NET Syntax (Toggle Plain Text)
Module Module1 Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo Sub Main() Do theKey = Console.ReadKey(True) Select Case theKey.Key Case ConsoleKey.X Exit Do Case ConsoleKey.N PrintScreen() End Select Loop End Sub Private Sub PrintScreen() Console.Write("000,000.00", 1234.5F) Console.WriteLine() End Sub End Module
Last edited by waynespangler; Mar 3rd, 2007 at 10:43 pm.
•
•
Join Date: Jun 2006
Posts: 117
Reputation:
Solved Threads: 0
Thank you! 
Now could i have you explain how it works?
I understand how most of it works, just not these two parts;

Now could i have you explain how it works?

I understand how most of it works, just not these two parts;
VB.NET Syntax (Toggle Plain Text)
Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo ..... ..... ..... theKey = Console.ReadKey(True)
•
•
Join Date: Jun 2006
Posts: 117
Reputation:
Solved Threads: 0
Ok, i figured out what the "theKey = Console.ReadKey(true)" does (that is why my code didn't work. I didn't use the "(true)".
Anyways, i still can't quite figure out what the purpose of the
is for
I know that it defines what theKey is, but why is it needed? (poor statement, yes, but i really don't see the need for it...)
Anyways, i still can't quite figure out what the purpose of the
VB.NET Syntax (Toggle Plain Text)
Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo
is for
I know that it defines what theKey is, but why is it needed? (poor statement, yes, but i really don't see the need for it...)
![]() |
Similar Threads
- Retrieve email I sent to the wrong person (Web Browsers)
- Dual booting questions (Windows Vista and Windows 7)
- NetBSD questions (*nix Software)
- Questions on Cookies (IT Professionals' Lounge)
- Some questions (PCI and Add-In Cards)
- Newbie questions about Linux servers and BSD (Getting Started and Choosing a Distro)
- Couple of CSS questions (HTML and CSS)
- Main Options / Style Questions (C++)
- connect to password protected access db (Visual Basic 4 / 5 / 6)
- 3d Program (Game Development)
Other Threads in the VB.NET Forum
- Previous Thread: Very easy problem- i can't seem to get
- Next Thread: barcode conversion in vb.net
| Thread Tools | Search this Thread |
.net .net2008 2008 access add advanced application array assignment basic beginner box browser button buttons center click client code combo convert cpu cuesent data database datagrid datagridview datetimepicker designer dissertation dissertations dissertationtopic eclipse editvb.net employees excel exists filter forms function html images isnumericfuntioncall listview map mobile module msaccess mssqlbackend mysql net number open page pan panel pdf picturebox picturebox2 port position print printing printpreview read record regex reuse right-to-left save search serial settings socket sorting sqldatbase sqlserver storedprocedure temp textbox timer timespan transparency txttoxmlconverter usercontol vb vb.net vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml year







