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. Using GetSystemTime in WM_KEYDOWN

Using GetSystemTime in WM_KEYDOWN

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 3 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.
  • E Offline
    E Offline
    EvScott
    wrote on last edited by
    #1

    I must be doing something really silly but I'm trying to get the time information when a key is hit down then released (WM_KEYUP). I'm writing a win32 application (doesn't anyone write these anymore?), but when I hit the key, I get a blank messagebox or squares. What am I doing wrong. Any good advice might win you a keg of cool beer or at least, a thanks. case WM_KEYDOWN: { SYSTEMTIME st; GetSystemTime(&st); MessageBox(NULL,(LPCWSTR)L"Time is "+ st.wMilliseconds,(LPCWSTR)L"Keystroke Analysis",MB_OK); } break; //etc

    _ CPalliniC 2 Replies Last reply
    0
    • E EvScott

      I must be doing something really silly but I'm trying to get the time information when a key is hit down then released (WM_KEYUP). I'm writing a win32 application (doesn't anyone write these anymore?), but when I hit the key, I get a blank messagebox or squares. What am I doing wrong. Any good advice might win you a keg of cool beer or at least, a thanks. case WM_KEYDOWN: { SYSTEMTIME st; GetSystemTime(&st); MessageBox(NULL,(LPCWSTR)L"Time is "+ st.wMilliseconds,(LPCWSTR)L"Keystroke Analysis",MB_OK); } break; //etc

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You cannot add a WORD type to a constant string. Use the Format method of the CString class to generate the Text for the MessageBox.

      «_Superman_»

      E 1 Reply Last reply
      0
      • E EvScott

        I must be doing something really silly but I'm trying to get the time information when a key is hit down then released (WM_KEYUP). I'm writing a win32 application (doesn't anyone write these anymore?), but when I hit the key, I get a blank messagebox or squares. What am I doing wrong. Any good advice might win you a keg of cool beer or at least, a thanks. case WM_KEYDOWN: { SYSTEMTIME st; GetSystemTime(&st); MessageBox(NULL,(LPCWSTR)L"Time is "+ st.wMilliseconds,(LPCWSTR)L"Keystroke Analysis",MB_OK); } break; //etc

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        EvScott wrote:

        doesn't anyone write these anymore?

        Yes. :rolleyes:

        case WM_KEYDOWN:
        {

        SYSTEMTIME st;
        GetSystemTime(&st);
        const int BUFSIZE = 0x100;
        TCHAR msg[BUFSIZE];
        HRESULT hr = StringCbPrintf(msg, sizeof(TCHAR) * BUFSIZE, _T("Time is %d"), st.wMilliseconds);

        if (SUCCEEDED(hr)) MessageBox(NULL, msg, _T("Keystroke Analysis"),MB_OK);
        }
        break;

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        E 1 Reply Last reply
        0
        • _ _Superman_

          You cannot add a WORD type to a constant string. Use the Format method of the CString class to generate the Text for the MessageBox.

          «_Superman_»

          E Offline
          E Offline
          EvScott
          wrote on last edited by
          #4

          Thanks.

          1 Reply Last reply
          0
          • CPalliniC CPallini

            EvScott wrote:

            doesn't anyone write these anymore?

            Yes. :rolleyes:

            case WM_KEYDOWN:
            {

            SYSTEMTIME st;
            GetSystemTime(&st);
            const int BUFSIZE = 0x100;
            TCHAR msg[BUFSIZE];
            HRESULT hr = StringCbPrintf(msg, sizeof(TCHAR) * BUFSIZE, _T("Time is %d"), st.wMilliseconds);

            if (SUCCEEDED(hr)) MessageBox(NULL, msg, _T("Keystroke Analysis"),MB_OK);
            }
            break;

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            E Offline
            E Offline
            EvScott
            wrote on last edited by
            #5

            Thanks,CPallini.I still get the same values when I include your example. However, when I run in debug mode and examine the values, I can see the SYSTEMTIME.wMilliSeconds. Just don't seem able to access it in a messagebox.

            CPalliniC 1 Reply Last reply
            0
            • E EvScott

              Thanks,CPallini.I still get the same values when I include your example. However, when I run in debug mode and examine the values, I can see the SYSTEMTIME.wMilliSeconds. Just don't seem able to access it in a messagebox.

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              I made a test, my code works on my system. Could you please post your updated code? Are you doing a UNICODE build? :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              E 1 Reply Last reply
              0
              • CPalliniC CPallini

                I made a test, my code works on my system. Could you please post your updated code? Are you doing a UNICODE build? :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                E Offline
                E Offline
                EvScott
                wrote on last edited by
                #7

                Thanks CPallini - Just don't seem to get a sensible output. I've omitted your code for reasons of clarity. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { SYSTEMTIME st; PAINTSTRUCT ps; switch (message) { case WM_PAINT: { HDC hdc = BeginPaint(hWnd,&ps); EndPaint(hWnd,&ps); } return(0); break; case WM_KEYDOWN: { SYSTEMTIME st; GetSystemTime(&st); //get duration in milliseconds } break; case WM_TIMER: { } break; case WM_KEYUP: { SYSTEMTIME st; GetSystemTime(&st); //get duration in milliseconds } break; case WM_DESTROY: // onload from memory PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }

                CPalliniC 1 Reply Last reply
                0
                • E EvScott

                  Thanks CPallini - Just don't seem to get a sensible output. I've omitted your code for reasons of clarity. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { SYSTEMTIME st; PAINTSTRUCT ps; switch (message) { case WM_PAINT: { HDC hdc = BeginPaint(hWnd,&ps); EndPaint(hWnd,&ps); } return(0); break; case WM_KEYDOWN: { SYSTEMTIME st; GetSystemTime(&st); //get duration in milliseconds } break; case WM_TIMER: { } break; case WM_KEYUP: { SYSTEMTIME st; GetSystemTime(&st); //get duration in milliseconds } break; case WM_DESTROY: // onload from memory PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Are you doing a UNICODE build? What is msg value at runtime, after the StringCbPrintf call (use the debugger to see)? :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  E 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    Are you doing a UNICODE build? What is msg value at runtime, after the StringCbPrintf call (use the debugger to see)? :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    E Offline
                    E Offline
                    EvScott
                    wrote on last edited by
                    #9

                    Thank you so much CPallini for you contribution. I made a small change to your original code by changing _T to L"" and it worked. Below is your code that I made small changes to. HRESULT hr = StringCbPrintf(msg, sizeof(TCHAR) * BUFSIZE, L"Time is %d", st.wMilliseconds); So I suppose all that's left is to ship that crate of cool beer to ya as promised in my original post. :laugh:

                    CPalliniC 1 Reply Last reply
                    0
                    • E EvScott

                      Thank you so much CPallini for you contribution. I made a small change to your original code by changing _T to L"" and it worked. Below is your code that I made small changes to. HRESULT hr = StringCbPrintf(msg, sizeof(TCHAR) * BUFSIZE, L"Time is %d", st.wMilliseconds); So I suppose all that's left is to ship that crate of cool beer to ya as promised in my original post. :laugh:

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #10

                      EvScott wrote:

                      I made a small change to your original code by changing _T to L"" and it worked.

                      Uhm, soooooooooo strange!

                      EvScott wrote:

                      So I suppose all that's left is to ship that crate of cool beer to ya as promised in my original post.

                      :beer: :-D :beer:

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      In testa che avete, signor di Ceprano?

                      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