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. some doubts about PeekMessage

some doubts about PeekMessage

Scheduled Pinned Locked Moved C / C++ / MFC
comjsonquestion
5 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.
  • W Offline
    W Offline
    winewind
    wrote on last edited by
    #1

    I want to do some test about keyboard loging without using hook api. in the following codz, i hope when i press Esc key, the prog will com to an end. but it seems PeekMessage() will never work, always failed. How could it be? Thanks a lot. #include "windows.h" #include "stdio.h" void main() { MSG msg; char buffer[10]; int i, ch; while(true) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) { if( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) break; //Esc pressed, then quit printf( "Enter a line: " ); /* Read in single line from "stdin": */ for( i = 0; i < 9; i++ ) { ch = getchar(); if(ch != '\n') buffer[i] = (char)ch; } /* Terminate string with null character: */ buffer[9] = '\0'; printf( "%s\n", buffer); *buffer=NULL; } else printf("peekmessage failed...\n"); Sleep(3000); //ensure there is enough time for keyboard operations } }

    Y 1 Reply Last reply
    0
    • W winewind

      I want to do some test about keyboard loging without using hook api. in the following codz, i hope when i press Esc key, the prog will com to an end. but it seems PeekMessage() will never work, always failed. How could it be? Thanks a lot. #include "windows.h" #include "stdio.h" void main() { MSG msg; char buffer[10]; int i, ch; while(true) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) { if( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) break; //Esc pressed, then quit printf( "Enter a line: " ); /* Read in single line from "stdin": */ for( i = 0; i < 9; i++ ) { ch = getchar(); if(ch != '\n') buffer[i] = (char)ch; } /* Terminate string with null character: */ buffer[9] = '\0'; printf( "%s\n", buffer); *buffer=NULL; } else printf("peekmessage failed...\n"); Sleep(3000); //ensure there is enough time for keyboard operations } }

      Y Offline
      Y Offline
      yndfcd
      wrote on last edited by
      #2

      Console Applications don't recieve windows messages.

      W 1 Reply Last reply
      0
      • Y yndfcd

        Console Applications don't recieve windows messages.

        W Offline
        W Offline
        winewind
        wrote on last edited by
        #3

        thank you so much. but can i use a keyboard or mouse hook api in console applications?

        Y 1 Reply Last reply
        0
        • W winewind

          thank you so much. but can i use a keyboard or mouse hook api in console applications?

          Y Offline
          Y Offline
          yndfcd
          wrote on last edited by
          #4

          No.You can't do that either.

          W 1 Reply Last reply
          0
          • Y yndfcd

            No.You can't do that either.

            W Offline
            W Offline
            winewind
            wrote on last edited by
            #5

            thank u so much^_^

            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