Couple of questions

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Couple of questions

 
0
  #1
Mar 2nd, 2007
I am using Visual Basic 2005 express (.net)

1) How would one get a SINGLE keypress in the console? (the equivilant to INKEY$ in QBASIC)

2) crap, i forgot my other question! Oh well. Chances are i will remember in a few minutes :lol:
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Couple of questions

 
0
  #2
Mar 2nd, 2007
A single key press?

What are you trying to do. I bet you can use a String for this instead.

And the console.readline()
Last edited by iamthwee; Mar 2nd, 2007 at 3:02 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Re: Couple of questions

 
0
  #3
Mar 3rd, 2007
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;

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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Re: Couple of questions

 
0
  #4
Mar 3rd, 2007
Bummer. I just read a few posts on other forums, and they all said that it can not be done.

Is there a way i could catch the key press from a WinAPI message?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Couple of questions

 
0
  #5
Mar 3rd, 2007
Originally Posted by Marks256 View Post
Bummer. I just read a few posts on other forums, and they all said that it can not be done.

Is there a way i could catch the key press from a WinAPI message?
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Couple of questions

 
0
  #6
Mar 3rd, 2007
arjunsasidharan is right.
On your form properties set the KeyPreview to true. Then use code simular to this:
  1. Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
  2. Select Case e.KeyChar
  3. Case "k", "K"
  4. MessageBox.Show("k was pressed")
  5. Case "x", "X"
  6. Me.Close()
  7. End Select
  8. End Sub
Last edited by waynespangler; Mar 3rd, 2007 at 9:45 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Re: Couple of questions

 
0
  #7
Mar 3rd, 2007
It is a console app. I know how to do it in a windows app (gui), but not in the console.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Couple of questions

 
0
  #8
Mar 3rd, 2007
Then try this:
  1. Module Module1
  2. Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo
  3.  
  4. Sub Main()
  5. Do
  6. theKey = Console.ReadKey(True)
  7. Select Case theKey.Key
  8. Case ConsoleKey.X
  9. Exit Do
  10. Case ConsoleKey.N
  11. PrintScreen()
  12. End Select
  13. Loop
  14. End Sub
  15.  
  16. Private Sub PrintScreen()
  17. Console.Write("000,000.00", 1234.5F)
  18. Console.WriteLine()
  19. End Sub
  20.  
  21. End Module
Hope this is what you want.
Last edited by waynespangler; Mar 3rd, 2007 at 10:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Re: Couple of questions

 
0
  #9
Mar 4th, 2007
Thank you!

Now could i have you explain how it works?

I understand how most of it works, just not these two parts;

  1. Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo
  2. .....
  3. .....
  4. .....
  5. theKey = Console.ReadKey(True)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 117
Reputation: Marks256 is an unknown quantity at this point 
Solved Threads: 0
Marks256 Marks256 is offline Offline
Junior Poster

Re: Couple of questions

 
0
  #10
Mar 4th, 2007
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
  1. 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...)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC