Re: keyboard input

On Sun, Feb 13, 2011 at 8:25 PM, Maximilian Schneider
<max schneidersoft net> wrote:
> Hello!
> I'm working on a CAD like program using input elements similar to
> inkscape; clicking the rectangle button or pushing the 'r' key.
> Whats the best way to implement something like this in C? I've taken a
> look at the inkscape source, but it being in C++, I can't make much use
> of it.

add a key press/release event handler for the window.

    switch (ev->keyval) {
    case GDK_KEY_foo:
          do_something ();

be careful about deciding whether you want to drive actions on press or release.

for better overall app design, make all "do_something()" methods into
GtkActions, and then

    switch (ev->keyval) {
    case GDK_KEY_foo:
            action = get_action ("do_something");
            action->activate ();

(the implementation of "get_action" is left as an exercise for the reader)

this then allows you to set up GUI elements like buttons as proxies
for the action, and then your entire GUI is nice and consistent.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]