Thread: fullscreen application blocks Windows functions

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    5

    fullscreen application blocks Windows functions

    Hi.
    I created a little program in C which is using the keybd_event() and GetAsyncKeyState() function.

    The purpose is to create an autowalk macro for a game. The program works perfect on the desktop.

    However, if I try to use it in the game (which runs in fullscreen), my program won't work. I guess that's because my program is somehow blocked by the game (maybe because it's demanding all resources, I am not sure why).

    How can I make sure my program will work anyway?

    I'd be thankful for hints!

    Thanks,
    moccajoghurt

    edit: here's the code:
    Code:
    #include <stdio.h>
    #include <Windows.h>
    
    int main(void) {
        
        printf("autowalk started. press \"num\" to start and stop.\n");
        
        int pressed = 0;
        int walk = 0;
        
        while (1) {
            
            if (GetAsyncKeyState(144) != 0 && pressed == 0) {
                
                pressed = 1;
                
                if (walk == 0) {
                    walk = 1;
                } else {
                    
                    walk = 0;
                }
                
            } else if (GetAsyncKeyState(144) == 0 && pressed == 1) {
                
                pressed = 0;
            }
            
            
            if (walk == 1) {
                keybd_event(87,0,0,0);
            }
            
            Sleep(10);
        }
    }
    Last edited by moccajoghurt; 09-10-2012 at 03:40 AM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You don't use the GetAsyncKeyState() correctly at all.

    Firstly, instead of magic numbers use the VK_* provided by Windows.
    Secondly, GetAsyncKeyState returns many info about the requested key, in order to find if it is pressed at the current time you do ((GetAsyncKeyState(vkey) & 0x8000) != 0)
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It's probably a property of the game. It is not uncommon, in full screen mode, for games to only accept actual keyboard input, and they often achieve that by hooking keyboard handlers (i.e. that gets into the system at a lower level than keybd_event() so effectively disable it from affecting the game). A fair few games do this, precisely to reduce chances of automated cheats, and to force players to actually play.

    Conversely, some development tools (eg Silverlight) also disable keyboard input completely in full-screen mode, as a security feature (since full screen applications can be transparent, a full-screen application can do keylogging, while the user thinks they are doing something else).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    5
    What exactly is GetAsyncKeyState(vkey) & 0x8000 doing? I have never used the "&" operator that way.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by moccajoghurt View Post
    What exactly is GetAsyncKeyState(vkey) & 0x8000 doing? I have never used the "&" operator that way.
    The 16th bit ( or the bit #15 ) indicates whether the key is pressed or not. Set if pressed, clear if not pressed.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running a Council Application without Code::Blocks
    By rssguar in forum C++ Programming
    Replies: 5
    Last Post: 02-09-2011, 09:43 AM
  2. test when my firewall blocks my application
    By Anddos in forum Networking/Device Communication
    Replies: 1
    Last Post: 09-04-2006, 11:46 PM
  3. Real fullscreen application
    By maxorator in forum Windows Programming
    Replies: 5
    Last Post: 11-05-2005, 10:43 AM
  4. Fullscreen application with DevC++
    By Queatrix in forum Windows Programming
    Replies: 7
    Last Post: 07-26-2005, 03:03 PM
  5. Switching from Windows to Fullscreen
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 06-16-2002, 02:15 PM