[RESOLVED] F-Keys, what's up with F10??
Folks,
I'm working on a CNC control program, based on a DLL that someone else wrote.
No problems with that sofar, as i get good support from the writer.
the problem i do have to tackle is the following:
I want to acces all the functions by means of softkeys ( the F-Keys at the top of our keyboards )
when the program starts it shows the Main menu softkeys ( F1-F12), and each F-key has a function assigned to it, some will make the machine move, others will show another menu, or a fileopen/save dialog, depending on the chosen keys.
all works fine and handy-dandy, except for the F10 key, it seems to be "Sticky", when i press it, the program will not react to any other key, only the F10 key can get it back in "normal state" accepting every key with a function assigned..
how to "unstick" the F10 after pressing it?.. because pressing F10 now, means no other key will do anything, and that may become dangerous, when the machine is moving and it must be stopped..
Thanks in advance
Re: F-Keys, what's up with F10??
This sounds more like a question for the writer of the program - we have no idea what the problem with the F10 key could be. We don't know what it does nor do we know what it is supposed to do.
Re: F-Keys, what's up with F10??
it has nothing to do with the dll, i experienced the same problem in another program i wrote, but i could avoid the problem by not assigning any functions to F10.
it looks like the F10 key acts as some sort of "On/Off" switch, press once to switch on, press again to switch off.
the code i use :
Code:
key = e.KeyValue
If key > 111 And key < 124 Then
softkey()
End If
If e.KeyCode = Keys.Left Then
cncapi.StartJog(0, -1, 1, 1)
End If
If e.KeyCode = Keys.Right Then
cncapi.StartJog(0, 1, 1, 1)
End If
where in the first "if/then" the keyvalue is retrieved, and a sub Softkey is called.
in this sub softkey, now all i do is display the keyvalue in a textbox, just for testing purposes, but lateron, it will furter call subroutines depending on which Fkey is pressed.
all the F-keys work fine, but only the F10 key "Stalls" the program, until i hit it again..
Re: F-Keys, what's up with F10??
I put together a quickie test
vb.net Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.F10
TextBox1.Text = "F10"
Case Keys.F5
TextBox2.Text = "F5"
Case Keys.F3
TextBox3.Text = "F3"
End Select
End Sub
I now know what you mean by "stuck"
I googled this problem and found a number of people posting the same question and/or reporting the issue.
I didn't find any resolution however.
Re: F-Keys, what's up with F10??
well, i found a solution for this problem, although it's a bit "quick'n'dirty"
if key = 121 ( value of F10) call a sub containing
Sendkeys.send(121)
so everytime i press F10 once, the program presses another time..
this happens before i call the sub with the assigned functions, so a multi-level menu is'nt harmed by this behaviour.
that seems to work sofar..
Re: F-Keys, what's up with F10??
It has to do with Menus. Normally (sic) F10 activates the menu. Press it now and if you have a menu bar the first item is highlighted.
I added a menu to Hack's example and then the code executed as expected.
Re: F-Keys, what's up with F10??
Adding e.Handled = True stops F10 from bubbling up. Works with / without menu.
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.F1
TextBox1.Text = "F1"
Case Keys.F2
TextBox1.Text = "F2"
Case Keys.F10
TextBox1.Text = "F10"
e.Handled = True
Case Else
TextBox1.Text = "other"
End Select
End Sub
Re: F-Keys, what's up with F10??
Case Keys.F10
TextBox1.Text = "F10"
e.Handled = True
Works well! :thumb:
Re: F-Keys, what's up with F10??
@hack - You a noob ;) Very funny.
Re: F-Keys, what's up with F10??
well.. to be honest.. i'm sort of a noob also, been writing VB.net for only some 7 months..
Gonna try e.Handled in my code also.. looks nicer than my solution..
Thanks a lot!:wave:
Re: F-Keys, what's up with F10??
Quote:
Originally Posted by
dbasnett
@hack - You a noob ;)
In VB.NET I am (can't you tell by some of my posts :rolleyes: )?
Re: [RESOLVED] F-Keys, what's up with F10??
Code:
key = e.KeyValue
If key > 111 And key < 124 Then
If key = 121 Then
e.Handled = True
End If
softkey.F_key()
End If
This is what i got in my code now, all keys except the Function keys are ignored, because of their Key-Value, and if you hit F10, well..you figured, e.handled is set to true..
Works like a Charm!...
Thanks again!