Numpad not working on the mac


#1

the number pad isn’t working on the mac

  • you can’t enter text into a texteditor with the number pad
  • in the key mapping component, keypad 9 shows up as keypad 0

also, key mappings for F13 - F16 don’t seem to work


#2

Ok, I’ve just been working on the Mac keyboard stuff so will look into this. Not sure how to test F13-F16 though, I’ve not got any of those!


#3

Here are the diffs to support F13 to F16. However, F14 & F15 are usually reserved by the system for LCD brightness. Here is some info on remapping them: http://www.xlr8yourmac.com/tips/remap_function_keys.html

I also fixed the number pad 9 bug, which was just a typo.

[code]==== //work/SDK/JUCE/1.42/build/macosx/platform_specific_code/juce_mac_Windowing.cpp#6 (text) ====

1266a1267,1268

  	105, KeyPress::F13Key, 107, KeyPress::F14Key,
  	113, KeyPress::F15Key, 106, KeyPress::F16Key, 			

1277c1279
< 91, KeyPress::numberPad8, 92, KeyPress::numberPad0,

        91, KeyPress::numberPad8, 92, KeyPress::numberPad9,

2782a2785,2786

  	105, KeyPress::F13Key, 107, KeyPress::F14Key,
  	113, KeyPress::F15Key, 106, KeyPress::F16Key, 			

3735a3740,3743

const int KeyPress::F13Key = 0x1011c;
const int KeyPress::F14Key = 0x1011d;
const int KeyPress::F15Key = 0x1011e;
const int KeyPress::F16Key = 0x1011f;

==== //work/SDK/JUCE/1.42/src/juce_appframework/gui/components/keyboard/juce_KeyPress.cpp#2 (text) ====

105c105
< || (keyCode >= KeyPress::F1Key && keyCode <= KeyPress::F12Key))

    || (keyCode >= KeyPress::F1Key && keyCode <= KeyPress::F16Key))

190c190
< for (int i = 1; i <= 12; ++i)

        for (int i = 1; i <= 16; ++i)

246c246
< if (keyCode >= F1Key && keyCode <= F12Key)

    if (keyCode >= F1Key && keyCode <= F16Key)

==== //work/SDK/JUCE/1.42/src/juce_appframework/gui/components/keyboard/juce_KeyPress.h#2 (text) ====

196a197,200

static const int F13Key;        /**< key-code for the F13 key */
static const int F14Key;        /**< key-code for the F14 key */
static const int F15Key;        /**< key-code for the F15 key */
static const int F16Key;        /**< key-code for the F16 key */[/code]

#4

On the PC, when I hit a key on the number pad, a component receives two KeyPress messages, on for the number pad key and one for the number.

On the mac, only one keypress message is received, the one for the number pad.

Which is the correct behavior?


#5

Thanks - I’d actually already done all that, apart from F16 which I couldn’t find the mac keycode for! I’ve also got some mac changes that do a better job of getting the unicode characters.

I think you might be right about the numpad keys on win32. In the doKeyDown() handler method, it’s probably best to remove the line that calls handleKeyPress() for those keys, because the doKeyChar() method will do the same callback later anyway.


#6

Ok, on the pc I fixed it by:

[code] bool isNumPadScan(int scan)
{
switch (scan)
{
case 0x52: // numpad 0
case 0x4F: // numpad 1
case 0x50: // numpad 2
case 0x51: // numpad 3
case 0x4B: // numpad 4
case 0x4C: // numpad 5
case 0x4D: // numpad 6
case 0x47: // numpad 7
case 0x48: // numpad 8
case x049: // numpad 9
return true;
default:
return false;
}
}

void doKeyChar (const WPARAM key, const LPARAM flags)
{
    const bool isAltGr = (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
                            == (ModifierKeys::ctrlModifier | ModifierKeys::altModifier);

    if ((currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) == 0
         || isAltGr
         || ! CharacterFunctions::isLetterOrDigit ((juce_wchar) key))
    {
        // if alt + ctrl are both down, this seems to indicate "alt gr", so we have
        // to temporarily disable these modifiers to make sure the characters typed
        // will be treated as normal keystrokes.
        if (isAltGr)
        {
            currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
        }
        else if ((currentModifiers & ModifierKeys::ctrlModifier) != 0
                  && key <= 31)
        {
            return;
        }
		
		int scan = (flags >> 16) & 0xFF;
		if (!CharacterFunctions::isDigit((juce_wchar)key) || !isNumPadScan(scan))
			handleKeyPress ((int) key);

        updateKeyModifiers();
    }
}[/code]

#7

the texteditor also needs:

else if (key.getKeyCode() >= KeyPress::numberPad0 && key.getKeyCode() <= KeyPress::numberPad9) { if (!isReadOnly()) { insertTextAtCursor(String(key.getKeyCode() - KeyPress::numberPad0)); } lastTransactionTime = Time::getApproximateMillisecondCounter(); }


#8

Nice one, thanks. I’ve got a slightly different solution for the next version, but it’ll do the same job.


#9