Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement key press event callbacks #3

Open
ewmailing opened this issue Jul 25, 2018 · 0 comments
Open

implement key press event callbacks #3

ewmailing opened this issue Jul 25, 2018 · 0 comments
Assignees
Labels

Comments

@ewmailing
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants