IupCocoa icon indicating copy to clipboard operation
IupCocoa copied to clipboard

implement key press event callbacks

Open ewmailing opened this issue 7 years ago • 0 comments

Iup has a key callback for most widgets called K_ANY and KEYPRESS_CB https://webserver2.tecgraf.puc-rio.br/iup/en/call/iup_k_any.html

  1. We have to detect a native key press on each specific widget

  2. Map the native keys that were pressed to the corresponding Iup keycodes. https://webserver2.tecgraf.puc-rio.br/iup/en/attrib/key.html Also may need to set MODKEYSTATE to record whether modifier keys are being pressed (control, alt, shift, option)

  3. Invoke the user's callback

  4. Check the user's return value from the callback and do the proper thing

This code should eventually be factored in a common place, but right now, the easiest place to start is directly code in iupcocoa_tree.m. There is a method called

  • (void) keyDown:(NSEvent*)the_event already there which captures all key presses when that tree instance in focus.

From there (2) you will need to find which keys are being pressed from the_event object. You will then map these to the Iup keycodes.

You invoke the user callback (3), following the usual Iup invoke callback conventions. This too should eventually be factored in a way we can call this for all widgets.

Then check the return value (4).

I think (but not completely sure):

In - (void) keyDown:(NSEvent*)the_event

If IUP_IGNORE: return immediately to end the method and don't do anything.

if IUP_CONTINUE: call [super keyDown:the_event]; and return.

If IUP_DEFAULT: return immediately to end the method and don't do anything. (this is the same as IUP_IGNORE, which is why I'm not completely sure)

if IUP_CLOSE: call IupExitLoop(); and return immediately.

Some info on Cocoa key events https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html

ewmailing avatar Jul 25 '18 13:07 ewmailing