コード例 #1
0
static gint
keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer ignored)
{
	int		note;
	char		*key;
	guint		keyval;
	GdkKeymapKey	kk;
	PianoKeyboard	*pk = PIANO_KEYBOARD(mk);

        (void) ignored;

	/* We're not using event->keyval, because we need keyval with level set to 0.
	   E.g. if user holds Shift and presses '7', we want to get a '7', not '&'. */
	kk.keycode = event->hardware_keycode;
	kk.level = 0;
	kk.group = 0;

	keyval = gdk_keymap_lookup_key(NULL, &kk);

	key = gdk_keyval_name(gdk_keyval_to_lower(keyval));

	if (key == NULL) {
		g_message("gtk_keyval_name() returned NULL; please report this.");
		return FALSE;
	}

	note = key_binding(pk, key);

	if (note < 0) {
		/* Key was not bound.  Maybe it's one of the keys handled in jack-keyboard.c. */
		return FALSE;
	}

	if (note == 128) {
		if (event->type == GDK_KEY_RELEASE) {
			rest (pk);
		}

		return TRUE;
	}

	note += pk->octave * 12;

	assert(note >= 0);
	assert(note < NNOTES);

	if (event->type == GDK_KEY_PRESS) {
		press_key(pk, note);

	} else if (event->type == GDK_KEY_RELEASE) {
		release_key(pk, note);
	}

	return TRUE;
}
コード例 #2
0
ファイル: rbgdkkeymap.c プロジェクト: Vasfed/ruby-gnome2
static VALUE
rg_lookup_key(VALUE self, VALUE keycode, VALUE group, VALUE level)
{
  GdkKeymapKey key;

  key.keycode = NUM2UINT(keycode);
  key.group = NUM2INT(group);
  key.level = NUM2INT(level);

  return INT2NUM(gdk_keymap_lookup_key(_SELF(self), &key));
}
コード例 #3
0
/* static */ PRUint32
KeymapWrapper::ComputeDOMKeyCode(const GdkEventKey* aGdkKeyEvent)
{
    guint keyval = aGdkKeyEvent->keyval;

    // First, try to handle alphanumeric input, not listed in nsKeycodes:
    // most likely, more letters will be getting typed in than things in
    // the key list, so we will look through these first.

    // since X has different key symbols for upper and lowercase letters and
    // mozilla does not, convert gdk's to mozilla's
    if (keyval >= GDK_a && keyval <= GDK_z) {
        return keyval - GDK_a + NS_VK_A;
    }
    if (keyval >= GDK_A && keyval <= GDK_Z) {
        return keyval - GDK_A + NS_VK_A;
    }

    // numbers
    if (keyval >= GDK_0 && keyval <= GDK_9) {
        return keyval - GDK_0 + NS_VK_0;
    }

    // keypad numbers
    if (keyval >= GDK_KP_0 && keyval <= GDK_KP_9) {
        return keyval - GDK_KP_0 + NS_VK_NUMPAD0;
    }

    // If the keyval indicates it's a modifier key, we should use unshifted
    // key's modifier keyval.
    if (GetModifierForGDKKeyval(keyval)) {
        KeymapWrapper* keymapWrapper = GetInstance();
        GdkKeymapKey key;
        key.keycode = aGdkKeyEvent->hardware_keycode;
        key.group = aGdkKeyEvent->group;
        key.level = 0;
        guint unshiftedKeyval =
            gdk_keymap_lookup_key(keymapWrapper->mGdkKeymap, &key);
        // But if the unshifted keyval isn't a modifier key, we shouldn't use
        // it.  E.g., Japanese keyboard layout's Shift + Eisu-Toggle key is
        // CapsLock.  This is an actual rare case, Windows uses different
        // keycode for a physical key for different shift key state.
        if (GetModifierForGDKKeyval(unshiftedKeyval)) {
            keyval = unshiftedKeyval;
        }
    }

    // map Sun Keyboard special keysyms
    for (PRUint32 i = 0; i < ArrayLength(kSunKeyPairs); i++) {
        if (kSunKeyPairs[i].GDKKeyval == keyval) {
            return kSunKeyPairs[i].DOMKeyCode;
        }
    }

    // misc other things
    for (PRUint32 i = 0; i < ArrayLength(kKeyPairs); i++) {
        if (kKeyPairs[i].GDKKeyval == keyval) {
            return kKeyPairs[i].DOMKeyCode;
        }
    }

    // function keys
    if (keyval >= GDK_F1 && keyval <= GDK_F24) {
        return keyval - GDK_F1 + NS_VK_F1;
    }

    return 0;
}