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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Blocking Certain Keyboard Input

Blocking Certain Keyboard Input

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtoolsquestion
2 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    Michael Sadlon
    wrote on last edited by
    #1

    I am not 100% sure how keyboard input works, so I thought I'd ask it here. I already asked about blocking joystick devices in C++, but I got no answers :doh: See here: http://www.codeproject.com/script/comments/forums.asp?msg=2038033&forumid=1647&mode=all&userid=4049045#xx2038033xx [^] Mostly, I am curious if there is a way to detect keyboard input from a "real keyboard" and differentiate it from a clicker/macro program. I want to do this in C++. I know there are WinAPI functions as well as Direct3d functions for such things, but I couldn't find any information on if it's possible to tell them apart. Any answers would be appreciated. Thanks in advance.

    P 1 Reply Last reply
    0
    • M Michael Sadlon

      I am not 100% sure how keyboard input works, so I thought I'd ask it here. I already asked about blocking joystick devices in C++, but I got no answers :doh: See here: http://www.codeproject.com/script/comments/forums.asp?msg=2038033&forumid=1647&mode=all&userid=4049045#xx2038033xx [^] Mostly, I am curious if there is a way to detect keyboard input from a "real keyboard" and differentiate it from a clicker/macro program. I want to do this in C++. I know there are WinAPI functions as well as Direct3d functions for such things, but I couldn't find any information on if it's possible to tell them apart. Any answers would be appreciated. Thanks in advance.

      P Offline
      P Offline
      Perspx
      wrote on last edited by
      #2

      You can use SetWindowsHookEx() with the WH_KEYBOARD_LL parameter to monitor all low-level keyboard messages. From the callback function, LowLevelKeyboardProc(), you can block any of the messages by returning a nonzero value, so that the message isn't sent to the target window. You could do something like this: ... //Prototypes LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); ... //Global variables HHOOK hLowlevelKeyboardHook; //Low-level keyboard hook handle ... //Main Window Callback function LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ... switch(msg) { case WM_CREATE: hLowlevelKeyboardHook=SetWindowsHookEx(WH_KEYBOARD_LL, //Low-level keyboard messages      LowLevelKeyboardProc, //Hook Callback function      NULL, //Monitor all system messages      0 //Monitor all system messages      ); break; } ... } ... LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { LPKBDLLHOOKSTRUCT kbdst; if(nCode<0) //No message to process return CallNextHookEx(hLowlevelKeyboardHook, nCode, wParam, lParam); //Block all keyboard messages, if they are the letter 'A' kbdst=(LPKBDLLHOOKSTRUCT)lParam; if(kbdst->vkCode==41) return -1; //Otherwise, send the message to the next hook return CallNextHookEx(hLowlevelKeyboardHook, nCode, wParam, lParam); } Hope this helps! --PerspX

      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