Decoding key down events 
Author Message
 Decoding key down events

Fellow RB users,
I am trying to implement a control that accepts a KeyDown event and
then parses it into its component modifier keys and key pressed. For
example, if user presses option-G -(generates the copyright sign)- I
want to decode it into "G" and "option key". I need this to do some
custom key bindings.

In C++, I used the KeyTranslate function, feeding it the EventRecord
generated by the user pressing a key. In RB, the KeyDown event takes a
string parameter from which I cannot get the virtual key code. ANy
help is appreciated.
Thanx



Mon, 17 Nov 2003 23:11:36 GMT  
 Decoding key down events

Quote:

> I am trying to implement a control that accepts a KeyDown event and
> then parses it into its component modifier keys and key pressed. For
> example, if user presses option-G -(generates the copyright sign)- I
> want to decode it into "G" and "option key".

This is a very difficult thing to do -- the whole point of characters
is that characters are NOT keys.  The copyright sign may be generated
by pressing option-G on your keyboard, but on my keyboard it may be
something completely different.

Quote:
> I need this to do some custom key bindings.

Hmm... there must be a better way to do key bindings than that.
Perhaps you can check the keyboard from a timer (using the Keyboard
object)?  Or, could you have menu items for all those key bindings
(thus relieving the user of the burden of having to remember them all
anyway)?

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Mon, 17 Nov 2003 23:59:29 GMT  
 Decoding key down events
How I can detect cursor keys without using TTs event monitor (for both
MacOs and Win32)? Thanx for info.

Frank



Tue, 18 Nov 2003 01:29:58 GMT  
 Decoding key down events

Quote:

> How I can detect cursor keys without using TTs event monitor (for both
> MacOs and Win32)? Thanx for info.

What's a cursor key?

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Tue, 18 Nov 2003 05:29:32 GMT  
 Decoding key down events

Quote:



> > How I can detect cursor keys without using TTs event monitor (for both
> > MacOs and Win32)? Thanx for info.

> What's a cursor key?

I think Frank's talking about the arrow keys.

Frank: Just filter for them in a KeyDown event somewhere. Or poll using
keyboard.AsyncKeyDown.

--
"In a world full of lies / That tug at the truth
 I'm taking no sides / Now I recognize you." -DS



Tue, 18 Nov 2003 10:47:56 GMT  
 Decoding key down events
Hello,

yess - I mean the arrow keys.
I have put this code in the keydown event of the main window:
(I dont need the "normal" keys, I need F-Keys, arrow keys etc. - the
normally returned key-string result is every empty)

---------------------------------------
  dim i,lst as integer

  lst= ???

  for i=0 to lst
    if keyboard.asynckeyDown(i) then
      info.text=str(i)
    end if
  next

  return true
---------------------------------------

How big is the value-area (range) of the keycodes?
I always get same (random?) results, that change only with the height of
"lst" but its not depend by the pressed key - whats the mistake?
I have tried for lst: 255, 1024, 32000, and 65000.

Please switch on the light in my brain ...

Frank



Tue, 18 Nov 2003 14:42:01 GMT  
 Decoding key down events

Quote:

> How big is the value-area (range) of the keycodes?

Please consult the language reference -- all the key codes are there on
a nice keyboard chart.  (Including the arrow keys.)  Note that the
chart appears only in the printed or PDF version, not the online
version in the IDE.

Also, you can indeed get KeyDown events for the arrow keys.  Prove this
to yourself by posting a message box with str(asc(key)) in the KeyDown
event of a window.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Tue, 18 Nov 2003 22:10:37 GMT  
 Decoding key down events

Quote:

>   dim i,lst as integer

>   lst= ???

>   for i=0 to lst
>     if keyboard.asynckeyDown(i) then
>       info.text=str(i)
>     end if
>   next

It looks like you're trying to get the keycode of whatever key was
pressed and display it somewhere -- correct?

If so, you'll always get the LARGEST keycode of any keys pressed (if
more than one are down), and I have encountered problems when using
keycodes that don't actually represent keys.  I imagine you're getting
false positive results because you're using values that are too high.

Somewhere in the Language Guide PDF, there's a keyboard map with all
keys labelled with their keycodes.  Find the largest one and use that.
I believe that value is 125.



Tue, 18 Nov 2003 22:28:10 GMT  
 Decoding key down events

Quote:
> Please consult the language reference -- all the key codes are there on
> a nice keyboard chart.  (Including the arrow keys.)

You could also fire up ResEdit and create a KCHR resource- then just type a
key and you will get the corresponding key code. Some key codes are in hex,
just convert them mentally. Example: F1 key- 7A or 122 (hopefully that's
right-I'm not that great at hexadecimal!)


Fri, 28 Nov 2003 09:42:53 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. key down event

2. Only One Tkinter Entry can receive key event event in Linux RH8.0

3. Reed-Solomon Decoding with decoding failure signal

4. VA Drop-down list problem with keys?

5. List box in source procedure - Up and Down Key not work

6. How to: Edit-in-place SPIN box and Up/Down arrow keys

7. Up/Down arrow key not working

8. Key up ,down ... sometimes don't work

9. Up/Down keys in Oberon/Linux

10. Question about handling of Up/Down Arrow keys

11. Bind the Up/Down Arrow Keys in my application

12. Shortcut keys for drop-down menus

 

 
Powered by phpBB® Forum Software