472,364 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

Capture Key Press

When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box it
works.

But when I try the same code on my application that has
text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?

Bob
+++++++++++++++

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
' The keypressed method uses the KeyChar property
to check
' whether the ENTER key is pressed.

' If the ENTER key is pressed, the Handled
property is set to true,
' to indicate the event is handled.

If e.KeyChar = Microsoft.VisualBasic.ChrW(65) Then
e.Handled = True
MsgBox("The following key was depressed " +
ChrW(65)) ' Display message that the " " was pressed
End If

End Sub
Nov 20 '05 #1
7 61896
Set the KeyPreview property on the form to true.

Then form will get all key events and allow you to specify if you have
handled the event. Do this with the handled property on the KeyPress/Key
Down/Key Up events.

Lloyd Sheen

"Bob Achgill" <an*******@discussions.microsoft.com> wrote in message
news:8f****************************@phx.gbl...
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box it
works.

But when I try the same code on my application that has
text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?

Bob
+++++++++++++++

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
' The keypressed method uses the KeyChar property
to check
' whether the ENTER key is pressed.

' If the ENTER key is pressed, the Handled
property is set to true,
' to indicate the event is handled.

If e.KeyChar = Microsoft.VisualBasic.ChrW(65) Then
e.Handled = True
MsgBox("The following key was depressed " +
ChrW(65)) ' Display message that the " " was pressed
End If

End Sub

Nov 20 '05 #2
Cool, it works!

Where is the table for all the ChrW(###) codes for
capturing KeyPresses?

I have tried from 1-256 can can't seem to find the cursor
Right/Left/Up/Down indexes.

-----Original Message-----
Set the KeyPreview property on the form to true.

Then form will get all key events and allow you to specify if you havehandled the event. Do this with the handled property on the KeyPress/KeyDown/Key Up events.

Lloyd Sheen

"Bob Achgill" <an*******@discussions.microsoft.com> wrote in messagenews:8f****************************@phx.gbl...
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box it works.

But when I try the same code on my application that has
text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?

Bob
+++++++++++++++

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
' The keypressed method uses the KeyChar property to check
' whether the ENTER key is pressed.

' If the ENTER key is pressed, the Handled
property is set to true,
' to indicate the event is handled.

If e.KeyChar = Microsoft.VisualBasic.ChrW(65) Then e.Handled = True
MsgBox("The following key was depressed " +
ChrW(65)) ' Display message that the " " was pressed
End If

End Sub

.

Nov 20 '05 #3
"Bob Achgill" <an*******@discussions.microsoft.com> schrieb
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box it
works.

But when I try the same code on my application that has
text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?


In addition to Lloyd, this might be of interest:

http://groups.google.com/groups?selm...ews.freenet.de
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Thanks! your suggestion lead me to find the "Key
Enumeration" list. In VB .Net doing a search
on "KeyEventArgs.KeyCode Property" and then clicking
on "Keys" will bring up the complete list of keycodes.

Among which are listed:
down Arrow returns 40
up arrow returns 38
left arrow returns 37
right arrow returns 39

I found this code and fixed it to work right to verify
what keycode is returned on pressing down any key.

It is pretty cool.

First make a form and then drag a text box on to it.
Then paste this into the code.

' ======================

Private Sub TextBox1_KeyDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles
TextBox1.KeyDown

TextBox1.Text = "Key pressed was " & e.KeyCode
End Sub
' ======================


-----Original Message-----
"Bob Achgill" <an*******@discussions.microsoft.com> schrieb
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box it works.

But when I try the same code on my application that has
text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?


In addition to Lloyd, this might be of interest:

http://groups.google.com/groups?selm=40955b3b%240%

2424800%249b622d9e%40news.freenet.de

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.

Nov 20 '05 #5
Do you see any way using my example keycode finder so I
don't have to put an Keydown event in each text box on my
form?

I tried making a keycode event at the form level but that
did not seem to catch the arrow key when the cursor focus
is on a text box with in the form.
-----Original Message-----
Thanks! your suggestion lead me to find the "Key
Enumeration" list. In VB .Net doing a search
on "KeyEventArgs.KeyCode Property" and then clicking
on "Keys" will bring up the complete list of keycodes.

Among which are listed:
down Arrow returns 40
up arrow returns 38
left arrow returns 37
right arrow returns 39

I found this code and fixed it to work right to verify
what keycode is returned on pressing down any key.

It is pretty cool.

First make a form and then drag a text box on to it.
Then paste this into the code.

' ======================

Private Sub TextBox1_KeyDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles
TextBox1.KeyDown

TextBox1.Text = "Key pressed was " & e.KeyCode
End Sub
' ======================


-----Original Message-----
"Bob Achgill" <an*******@discussions.microsoft.com>

schrieb
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Boxit works.

But when I try the same code on my application that has text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?


In addition to Lloyd, this might be of interest:

http://groups.google.com/groups?selm=40955b3b%240%

2424800%249b622d9e%40news.freenet.de


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.

.

Nov 20 '05 #6
My appologies for my short memory.

I think either you or Loyd gave me this answer already...

Set KeyPreview() = True at the form level to allow
catching arrow or any key downs regardless of where the
cursor focus is on the form

The following code fixes my keyfinder to work anywhere on
the form.
===================
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
KeyPreview() = True ' Allows catching arrow
key at over all form level using Keydown event

End Sub
===================
-----Original Message-----
Do you see any way using my example keycode finder so I
don't have to put an Keydown event in each text box on myform?

I tried making a keycode event at the form level but thatdid not seem to catch the arrow key when the cursor focusis on a text box with in the form.
-----Original Message-----
Thanks! your suggestion lead me to find the "Key
Enumeration" list. In VB .Net doing a search
on "KeyEventArgs.KeyCode Property" and then clicking
on "Keys" will bring up the complete list of keycodes.

Among which are listed:
down Arrow returns 40
up arrow returns 38
left arrow returns 37
right arrow returns 39

I found this code and fixed it to work right to verify
what keycode is returned on pressing down any key.

It is pretty cool.

First make a form and then drag a text box on to it.
Then paste this into the code.

' ======================

Private Sub TextBox1_KeyDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles
TextBox1.KeyDown

TextBox1.Text = "Key pressed was " & e.KeyCode
End Sub
' ======================


-----Original Message-----
"Bob Achgill" <an*******@discussions.microsoft.com>

schrieb
When I use the code for KeyPress to capture pressing a certain key for processing on a form with no Text
Box
it
works.

But when I try the same code on my application that

has text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?

In addition to Lloyd, this might be of interest:

http://groups.google.com/groups?selm=40955b3b%240%

2424800%249b622d9e%40news.freenet.de


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.

.

.

Nov 20 '05 #7
OK. Am I missing something. The following code captures
the cursor keys alright on the form for everywhere except
when the focus is on a DataGrid or AxWebBrowser.

Yes i have set the KeyPreview property on the form to
true. Almost home!
' +++++++++++++++++++++++++++++++++++++++++++++++
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles
MyBase.KeyDown

If e.KeyCode = 37 Then ' Cursor left
If e.KeyCode = 39 Then ' Cursor right

End Sub
' ++++++++++++++++++++++++++++++++++++++++++++++++
-----Original Message-----
Cool, it works!

Where is the table for all the ChrW(###) codes for
capturing KeyPresses?

I have tried from 1-256 can can't seem to find the cursorRight/Left/Up/Down indexes.

-----Original Message-----
Set the KeyPreview property on the form to true.

Then form will get all key events and allow you tospecify if you have
handled the event. Do this with the handled property onthe KeyPress/Key
Down/Key Up events.

Lloyd Sheen

"Bob Achgill" <an*******@discussions.microsoft.com>

wrote in message
news:8f****************************@phx.gbl...
When I use the code for KeyPress to capture pressing a
certain key for processing on a form with no Text Box

it works.

But when I try the same code on my application that has text boxes it does does not work.

How can I capture the cursor left and right keys for
processing?

Bob
+++++++++++++++

Private Sub Form1_KeyPress(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
' The keypressed method uses the KeyCharproperty to check
' whether the ENTER key is pressed.

' If the ENTER key is pressed, the Handled
property is set to true,
' to indicate the event is handled.

If e.KeyChar = Microsoft.VisualBasic.ChrW(65)Then e.Handled = True
MsgBox("The following key was depressed " + ChrW(65)) ' Display message that the " " was pressed
End If

End Sub

.

.

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
1
by: ywchan | last post by:
I would like to have a datagrid that can be edited but not delete... and I have no idea how to capture the del key press event. Please help, thank!
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
4
by: Mike R | last post by:
Hi, Could someone give me a pointer to do the following: I would like to capture a keystroke from "anywhere" , i.e If the user is in Word, Excel, Myother app, desktop etc... and they press...
2
by: ghostrider | last post by:
Hi, I am working on an access app and need to capture still images from a monitor connected to medical equipment. The video out port on the monitor is connected to a video card in the computer...
5
by: Muffin | last post by:
I am trying to capture the out put of a command line program. Let say ping or maybe better yet nslookup. I would like to launch and then capture all the output , redirect it I guess to a string...
3
by: mike | last post by:
Hi Guys, Following piece of code can capture IOError when the file doesn't exist, also, other unknown exceptions can be captured when I press Ctrl-C while the program is sleeping(time.sleep)....
0
by: ikramalikhan | last post by:
i am developing a software in vb 6.0 as front end and msaccess as back end..i want to capture an ultrasound image via my vb form image control.my doctor client will capture live ultrasound image and...
2
by: slinky | last post by:
I, as others, routinely do a screen capture by using "Alt+Print Screen". Is there a way to program this as an event to a button control for the user to press? Thanks!
1
by: anil | last post by:
I want to capture key down event in the window service and open a new app when the user press F7. Is there any solution available in C#
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.