473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What is the syntax for detecting function key events?

Does someone know the syntax to detect when certain function keys are
pressed?
Nov 15 '05 #1
4 17452
For any object that has the keyDown event, you can use (example for a form
named Form1):

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if (e.KeyCode == Keys.F1) DoSomething();
}

hope that helps....
Cata

"Sean Connery" <nf*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Does someone know the syntax to detect when certain function keys are
pressed?

Nov 15 '05 #2
100
Hi Sean,
There is no method in the framework to check the key state except for the
modifier keys (CTRL, SHIFT and ALT).
You have to use KeyDown/Up events or P\Invoke to use the API functions for
that.

B\rgds
100

"Sean Connery" <nf*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Does someone know the syntax to detect when certain function keys are
pressed?

Nov 15 '05 #3
For some reason, I am not snagging the event. I have created a base child
form where the derived child form is embedded within an MDI parent
container. The child form is in focus and when I press the appropriate
function key, no event is fired.

My test code looks as follows:
private void ChildViewBase_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F1:
F1KeyPressed();
break;
case Keys.F2:
F2KeyPressed();
break;
}

protected virtual void F1KeyPressed() {}
protected virtual void F2KeyPressed() {}
"Catalin Stefan Goilav" <ca**@bsc.ro> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
For any object that has the keyDown event, you can use (example for a form
named Form1):

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.F1) DoSomething();
}

hope that helps....
Cata

"Sean Connery" <nf*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Does someone know the syntax to detect when certain function keys are
pressed?


Nov 15 '05 #4
Found it. Needed to implement the IMessageFilter interface.

"Sean Connery" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
For some reason, I am not snagging the event. I have created a base child
form where the derived child form is embedded within an MDI parent
container. The child form is in focus and when I press the appropriate
function key, no event is fired.

My test code looks as follows:
private void ChildViewBase_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F1:
F1KeyPressed();
break;
case Keys.F2:
F2KeyPressed();
break;
}

protected virtual void F1KeyPressed() {}
protected virtual void F2KeyPressed() {}
"Catalin Stefan Goilav" <ca**@bsc.ro> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
For any object that has the keyDown event, you can use (example for a form named Form1):

private void Form1_KeyDown(object sender,

System.Windows.Forms.KeyEventArgs
e)
{
if (e.KeyCode == Keys.F1) DoSomething();
}

hope that helps....
Cata

"Sean Connery" <nf*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Does someone know the syntax to detect when certain function keys are
pressed?



Nov 15 '05 #5

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

Similar topics

1
by: Mark Szlazak | last post by:
Is there a way to detect if an textarea onscroll event is working in Firefox (or Mozilla). I know that there is an onscroll event bubbling bug with current vesions of these browsers so I want to...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
9
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they...
5
by: Charlie | last post by:
How do I determine if the user has pressed the tab key? The Keypress and Keydown events fire for other keys, but not the tab.
7
by: EliteBadger | last post by:
Hey, I've searched around on Google Groups for a while on this topic, and haven't found anything useful. I use a FileSystemWatcher to catch filesystem events. I would also like to get an event...
4
by: almurph | last post by:
Hi everyone, I'm a newbie to javascript. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a...
8
by: squash+go | last post by:
For an abstract algebra class that I will be teaching, I'm trying to convert a text-based game that I wrote in Common Lisp to a graphical game in javascript. (I know nothing of javascript, but I...
15
by: RobG | last post by:
When using createEvent, an eventType parameter must be provided as an argument. This can be one of those specified in DOM 2 or 3 Events, or it might be a proprietary eventType. My problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.