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. simulating keyboard input with SetKeyboardState

simulating keyboard input with SetKeyboardState

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.
  • S Offline
    S Offline
    Spiritofamerica
    wrote on last edited by
    #1

    hello I am experimenting with simulating a key press using the SetKeyboardState while(true) { DWORD thread_acum=GetWindowThreadProcessId(GetActiveWindow(),NULL); UINT vk,scan; LPARAM lparam; vk = VkKeyScan('s'); AttachThreadInput(thread_acum,GetCurrentThreadId(),TRUE); BYTE byKeybState[256]; GetKeyboardState(byKeybState); byKeybState[vk] =! (BOOL)::GetKeyState(vk); byKeybState[vk] =!(BOOL)GetKeyState(vk); SetKeyboardState(byKeybState); AttachThreadInput(thread_acum,GetCurrentThreadId(),FALSE); Sleep(1000); } why does this not work? No key is pressed

    T 1 Reply Last reply
    0
    • S Spiritofamerica

      hello I am experimenting with simulating a key press using the SetKeyboardState while(true) { DWORD thread_acum=GetWindowThreadProcessId(GetActiveWindow(),NULL); UINT vk,scan; LPARAM lparam; vk = VkKeyScan('s'); AttachThreadInput(thread_acum,GetCurrentThreadId(),TRUE); BYTE byKeybState[256]; GetKeyboardState(byKeybState); byKeybState[vk] =! (BOOL)::GetKeyState(vk); byKeybState[vk] =!(BOOL)GetKeyState(vk); SetKeyboardState(byKeybState); AttachThreadInput(thread_acum,GetCurrentThreadId(),FALSE); Sleep(1000); } why does this not work? No key is pressed

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      Spiritofamerica wrote: SetKeyboardState Why Don't you use SendInput Api or KeyBD_event api..

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV

      S 1 Reply Last reply
      0
      • T ThatsAlok

        Spiritofamerica wrote: SetKeyboardState Why Don't you use SendInput Api or KeyBD_event api..

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV

        S Offline
        S Offline
        Spiritofamerica
        wrote on last edited by
        #3

        because I have the latest version of zonealarm installed on my sytem and it doesn't allow these functions any more I am not trying to do anything illegal with this but I saw it in a article and said hey I should try this and it doesn't work So far za doesn't object to me using this function but it doesn't work for the others you mention above and for PostMessage(WM_KEYUP) it gives me worning messages so there are 2 reasons 1. I don't wanna upset za 2.I wanna do it with this function

        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