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. Keyboard and Mouse State

Keyboard and Mouse State

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

    Hi all I'm wanting to retrieve the current keyboard and mouse state without having to wait for an event message. I basically have a main thread and a window thread. The window thread handles the windows message pump so that if my app locks up, it can still process close messages etc. The main thread is where I am wanting to do the device state reads. Everything I've looked at so far (RAWINPUT, SetWindowsHookEx) rely on an event message being posted before I am able to read the state from the device. This is no good to me. I've also looked at GetKeyboardState(..) but that only retrieves the keyboard state in the thread that is handling the windows messages, so calling it from the main thread does not work (but calling it from the window thread does). I'm starting to think the only way is to get access to the device driver and directly read from the device. Anyone know any decent articles on this? Thanks, Alan.

    "When I left you I was but the learner, now I am the master" - Darth Vader

    N 1 Reply Last reply
    0
    • A Alan Chambers

      Hi all I'm wanting to retrieve the current keyboard and mouse state without having to wait for an event message. I basically have a main thread and a window thread. The window thread handles the windows message pump so that if my app locks up, it can still process close messages etc. The main thread is where I am wanting to do the device state reads. Everything I've looked at so far (RAWINPUT, SetWindowsHookEx) rely on an event message being posted before I am able to read the state from the device. This is no good to me. I've also looked at GetKeyboardState(..) but that only retrieves the keyboard state in the thread that is handling the windows messages, so calling it from the main thread does not work (but calling it from the window thread does). I'm starting to think the only way is to get access to the device driver and directly read from the device. Anyone know any decent articles on this? Thanks, Alan.

      "When I left you I was but the learner, now I am the master" - Darth Vader

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Alan Chambers wrote:

      I've also looked at GetKeyboardState(..) but that only retrieves the keyboard state in the thread that is handling the windows messages, so calling it from the main thread does not work (but calling it from the window thread does).

      Not sure because I have not used this function much, but anyway MSDN says this... The status does not change as keyboard messages are posted to the thread's message queue, nor does it change as keyboard messages are posted to or retrieved from message queues of other threads. (Exception: Threads that are connected through **AttachThreadInput** share the same keyboard state.) Does that help?

      Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      A 1 Reply Last reply
      0
      • N Nibu babu thomas

        Alan Chambers wrote:

        I've also looked at GetKeyboardState(..) but that only retrieves the keyboard state in the thread that is handling the windows messages, so calling it from the main thread does not work (but calling it from the window thread does).

        Not sure because I have not used this function much, but anyway MSDN says this... The status does not change as keyboard messages are posted to the thread's message queue, nor does it change as keyboard messages are posted to or retrieved from message queues of other threads. (Exception: Threads that are connected through **AttachThreadInput** share the same keyboard state.) Does that help?

        Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

        A Offline
        A Offline
        Alan Chambers
        wrote on last edited by
        #3

        Hi thanks for the reply, but it doesn't really help me. I've read the MSDN articles pretty thoroughly and that function basically only works on threads which have created a window using CreateWindow or CreateWindowEx and have a message pump. Since I've created the window on a separate thread, GetKeyboardState() only actually works if it's called within that threads loop, but it won't work on another thread unless AttachThreadInput() is used to share the message processing. However, AttachThreadInput() cannot be attached from or to the system thread (which is the one i'm using for my app) and in any case it would need to be a thread that has created a window and uses a windows message pump as well, which it does not. Looks like what I'm after is quite low-level, raw device state reading functionality but all I'm seeing is Windows event driven solutions. There's got to be a way to bypass all this windows guff and read directly from whatever hardware is present..surely..? Cheers for trying tho :) Alan.

        "When I left you I was but the learner, now I am the master" - Darth Vader

        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