keyStateChanged does not detect delete key on Windows


Hi, I need to detect Delete key when it is pressed and released. My app logic is so, some codes should run as long as Delete key is pressed and is held in pressed state. As soon as the user releases the delete key that part of code should not run anymore. I thought using "keyStateChanged" function is the right way to go, and it works fine on OSX, but on Windows it does nothing. Actually it seems it cannot detect the delete key in pressed state on Windows. Code below is some part of what I am doing:


in header file:






in cpp:

bool MainContentComponentUI::keyStateChanged (bool isKeyDown, Component originatingComponent)
   if((KeyPress::isKeyCurrentlyDown(KeyPress::deleteKey)) ||
       (KeyPress::isKeyCurrentlyDown(DELETEKEOSXKEYCODE)) ||
       (KeyPress::isKeyCurrentlyDown(BACKSPACEOSXKEYCODE)) ||
       (KeyPress::isKeyCurrentlyDown(CNRLBACKSPACEOSXKEYCODE)) ||
       (KeyPress::isKeyCurrentlyDown(DELETEWINOWSKEYCODE)) ||
       (KeyPress::isKeyCurrentlyDown(KeyPress::numberPadDelete )) ||
      deleteKeyIsDown = true;
      deleteKeyIsDown = false;

  return false;

As you can see I added all the possible keycodes that is generated by Delete key on Windows and OSX, but the condition is never true and  deleteKeyIsDown is always false. That would be great if someone could give me a hint.



What's going on with the nasty hard-coded numbers? Where did the values even come from?


I catched the key codes for Del and Backspace in OSX and Windows, with and without modifiers. For example on OSX the key code for Delete is 63272.

As you see I used OR logic so if any of them are true, the condition becomes true. The problem is that, on windows using any of the key codes, I am not able to detect Delete key down state. As I said, I need to detect when the Del key is down and when it is released. It works fine on OSX but on windows it does not.

I see in juce_win32_Windowing.cpp file that you defined "KeyPress::deleteKey  = VK_DELETE" which VK_DELETE is 0x2E or 46. The weired thing is that, on my keyboard the key "." generates code 46.

I am developing on OSX, running Windows 7 on virtual box. I use a German keyboard.


But those constants are different on every platform - you can't just hard-code the numbers, you'd need to use the values that are provided via KeyPress::deleteKey etc (?)


As you see the first condition in the if is KeyPress::deleteKey, let's ignore other conditions as it is a OR logic. Could you please test, whether you can detect key down and key released for Delete key on windows inside keyStateChanged function?


Hi ehsanen, there was in deed a bug where some of the key-codes were incorrectly translated in the isKeyCurrentlyDown method on Windows. This should be fixed on the latest tip now and you should be able to detect the delete key with KeyPress::deleteKey on all platforms. Thank you for reporting!


Yes, that solved the problem. Thank you very much.