OnKeyPress question

In this category you can exchange your programming questions and solutions.
Post Reply
Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

OnKeyPress question

Post: # 250Post Fazer
Wed May 14, 2008 5:21 pm

The button has an event, which is called "OnKeyPress". It works fine - I know the button must have the focus -, but  how can I find out, which key is pressed?

The key table describes the key numbers for keyDown and keyUp events with a variable "key" (format WORD),
but how does this work with "OnKeyPress", because a button has no "keyDown" or "keyUp" events.

I know this from other basics but I tried it out, but every try gave an error.

How can I catch the type of the pressed key?

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

OnKeyPress question

Post: # 251Post Fazer
Fri May 16, 2008 8:30 am

Yes, I found the answer by myself:

What I`m looking for works only in an edit control with the events:

? ? ? OnKeyDown ?: ?" Sub([edit,] key, shift). A sub-routine calls if a key is pressed."

? ? ? OnKeyUp ?: ?" Sub([edit,] key, shift). A sub-routine calls if a key is released."

What do we learn from this:
? ? ? ?If you have a problem read the Help - file more exactly !

The Help file of FNXBasic is not as perfect as it could be, but it does what it has to do.

?


PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

OnKeyPress question

Post: # 252Post PaPi
Fri May 16, 2008 7:34 pm

I know this with object EDIT. But what about the object BUTTON? You did want use with BUTTON
this events, didn`t you?
PaPi

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

OnKeyPress question

Post: # 253Post Fazer
Sat May 17, 2008 6:04 am



I think a button only can see if a key is pressed, but not which key. Is this right ?

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

OnKeyPress question

Post: # 254Post Marco
Mon May 19, 2008 3:43 pm

Hi you can detect which button is pressed, only the keys not the special keys.

object f as form
 object b as button
   onkeypress=kp
 end object
end object
f.showmodal

sub kp(key as integer)
  showmessage str$(key)
end sub

I hope this will help you out
best regards

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

OnKeyPress question

Post: # 255Post Fazer
Mon May 19, 2008 8:08 pm

Many thanks, this helps a lot.

The Help file gives only the information:

"OnKeyPress:  Sub([button]). A sub-routine calls if a key is pressed."

I looked for a "key" variable in the format "word" as described at the event "onkeydown" with the edit control.
I dont`expected an integer.

The help should give more infos.

Post Reply