Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Swallow a keyup

Swallow a keyup

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rozis
    wrote on last edited by
    #1

    This is a part 2 on a question i posted earlier on this forum. The problem: In a Keydown handler, when a user pressed the VK_MENU key an editbox is created. So far so good. Problem is that the standard behaviour of windows for a KEYUP-message of this key is to open a context menu. I was suggested: 1) to create the editbox in the keyup handler. This is not an option. 2) to swallow the keyup-message. This sounds good. My question: how to swallow the keyup message? Is it setting up a local message dispatcher that dispatches messages till the keyup event comes in view, and then just trow it away? What happens to the keyboardstate then? I'm using C. A light on the right approach would be welcome... Rozis

    I 2 Replies Last reply
    0
    • R Rozis

      This is a part 2 on a question i posted earlier on this forum. The problem: In a Keydown handler, when a user pressed the VK_MENU key an editbox is created. So far so good. Problem is that the standard behaviour of windows for a KEYUP-message of this key is to open a context menu. I was suggested: 1) to create the editbox in the keyup handler. This is not an option. 2) to swallow the keyup-message. This sounds good. My question: how to swallow the keyup message? Is it setting up a local message dispatcher that dispatches messages till the keyup event comes in view, and then just trow it away? What happens to the keyboardstate then? I'm using C. A light on the right approach would be welcome... Rozis

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      If you're fixated on WM_KEYDOWN, rather than WM_KEYUP, you have another problem to consider. When someone holds down a key, you get multiple down messages, followed by a single up message. Are you requiring someone to hold down the menu button? If not, what's wrong with using the UP message? If you are requiring they hold down this button, then a) typing will be hard, and b) you could use the up button to dismiss your edit box. Answering your question more directly, if you can handle the down message, can't you just handle the up message with 99% identical code:

      case WM_KEYDOWN:
      if (wParam == VK_MENU)
      DoSomething ();
      else
      DoAnotherThing ();
      break;

      case WM_KEYUP:
      if (wParam == VK_MENU)
      ;
      else
      DoYetAnotherThing ();
      break;

      You say you're using C, so I assume some win32 code stuff. Yours trying to help but puzzled why your tying your shoe laces together, Iain.

      I have now moved to Sweden for love (awwww).

      1 Reply Last reply
      0
      • R Rozis

        This is a part 2 on a question i posted earlier on this forum. The problem: In a Keydown handler, when a user pressed the VK_MENU key an editbox is created. So far so good. Problem is that the standard behaviour of windows for a KEYUP-message of this key is to open a context menu. I was suggested: 1) to create the editbox in the keyup handler. This is not an option. 2) to swallow the keyup-message. This sounds good. My question: how to swallow the keyup message? Is it setting up a local message dispatcher that dispatches messages till the keyup event comes in view, and then just trow it away? What happens to the keyboardstate then? I'm using C. A light on the right approach would be welcome... Rozis

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        I've been curious and looked at your previous question. I've made a small app, and it has an edit box. Both right clicking in the edit box, and pressing the menu key end up generating a WM_CONTEXTMENU message. *This* is what pops up the menu. You could subclass the edit window in question, and handle the WM_CONTEXTMENU message for that window. Handle it by doing very little. The details of how you do that vary a lot depending on what programming framework you are using. Iain.

        I have now moved to Sweden for love (awwww).

        R 1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          I've been curious and looked at your previous question. I've made a small app, and it has an edit box. Both right clicking in the edit box, and pressing the menu key end up generating a WM_CONTEXTMENU message. *This* is what pops up the menu. You could subclass the edit window in question, and handle the WM_CONTEXTMENU message for that window. Handle it by doing very little. The details of how you do that vary a lot depending on what programming framework you are using. Iain.

          I have now moved to Sweden for love (awwww).

          R Offline
          R Offline
          Rozis
          wrote on last edited by
          #4

          Hi Iain, Thank you for your answers, and the time to get the answer. Of course you're right about the button down vs button up. I have to reconcider that. But actually you found out how it really works (WM_CONTEXTMENU). So i'll track that one and throw in the void... Thanks again Rozis

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups