GetAsyncKeyState() causes anti-virus program to flag as keylogger - winapi

I have been building a very small game in the Windows API, and in the main message loop I use GetAsyncKeyState() to test if a user is pressing the arrow buttons. I use this instead of WM_KEYDOWN because with WM_KEYDOWN there is an initial pause after the first press, and I don't want to modify a user's settings. My antivirus program flags the game as a keylogger program, is there an alternative way about this?

How is the anti-virus program supposed to guess that you are not using GetAsyncKeyState() to spy on the keyboard and log keys? You tell it of course, make an exclusion. If you're worried that your future customers are not so easily convinced then go back to using WM_KEYDOWN/UP. Use an array of 256 bools to keep track of the key state. Set it to true on DOWN, regardless of how many you get, false on UP. Also check if the scanner is happy when you stop calling the API function when your app loses focus. Pay attention to WM_ACTIVATEAPP.

Related

Using KeyRemap4MacBook to bind a keyboard key to a scroll action?

Basically, I want to bind a certain letter to scroll up the mouse reel, and do so continuously if I hold the key continuously. I need it to work even if other keys are being pressed at the same time, and only work on a certain window title/tab title in the browser.
I basically want to emulate the function of the autohotkey program for the "Attack On Titan Tribute Game"'s reeling function.
An AutoHotKey equivalent is available at:
http://fenglee.com/forum/viewtopic.php?f=2&t=7548
(Which may be offline due to unknown reasons, might have to wait)
Basically, if you download the application, set Reel In to the "x" or "e" key, it works regardless if other keys are being held. Just make sure you uncheck the checkbox so it can work in any window. It basically scrolls down for you. It also includes the source.
Or.. if I can use any other free application to do the same thing, that'd be nice.
All I want is the scrolling function and it has to be specific to a window/plugin/etc. and be able to be triggered while holding down other keys.

GetAsyncKeyState() fails to return state of keyboard/mouse, while WM_KEYDOWN messages seem to work fine

I'm writing a game where I use GetAsyncKeyState() for character control like WASD and mouse buttons, and the windows messaging system for menu stuff like text input and cursor control.
Every once in a while, my computer seems to get into this weird state where GetAsyncKeyState() doesn't return anything. It seems to be related to times when my game crashes. Once the computer is in this state, I don't know how to get it out unless I restart the computer.
The windows messaging system still works fine in this case- if I type the 'W' key, I still get a WM_KEYDOWN message and the letter can show in my menu system, but the following method, which normally works, will fail:
bool result = (GetAsyncKeyState(vkey) & 0x8000) != 0;
For all I know, this is being caused by an external program (such as Synergy+, which I use to share mouse/keyboard input between computers), however I haven't been able to prove this yet.
Whatever the cause, I don't want this problem to occur to an end user. Are there any techniques to diagnose and repair a state like this?
EDIT: Perhaps this is some kind of driver issue? I just noticed that when my computer gets in this state, my mouse no longer processes the shortcuts I've assigned to its extra buttons. I don't know enough about how all this works to know what to blame in a case like this.

Is it possible to programmatically prevent a game from pausing when its window loses focus?

I'm playing Skyrim in windowed mode and I am trying to create a bot for this game for personal use. I would like to have the bot play the game in the background, while I do other things, the only problem is that the game window pauses when it loses focus. Is there a way to make the Skyrim process think that it still has the focus, so it continues to run while I do something else on another window? I'm not a windows programming expert but would this be possible if I could somehow intercept the message that says unfocused or minimized to the process, and thus let the process think its still focused?
It's possible. You need to find the mechanism through which the game checks whether it's in the foreground then trick it into thinking the switch has not occurred. This will require a certain amount of reverse engineering on your part. There are many different ways that this checking can actually be done by the game.
You can try to play with hooking one of the following messages/functions: WM_KILLFOCUS, WM_ACTIVATE, GetForegroundWindow. On the other hand, the game might be doing something funky with DirectX. I don't have much experience there.
To re-iterate, to do this properly you are really going to have to find out exactly how the game does the checking (and then subvert that).

Best way to intercept pressing of Caps Lock

What is the best way to intercept the Caps Lock button on Windows, for making a program like Launchy?
Currently, I'm setting a low-level hook with SetWindowsHookEx, but that's a bit too low-level for me, since I don't want to intercept other programs that are trying to be active a low level. I'm looking for the highest possible level of interception that can still prevent turning on Caps Lock itself... any better suggestions?
You can use RegisterHotKey:
RegisterHotKey(hWnd, 0, 0, VK_CAPITAL);
Your window will receive a WM_HOTKEY message whenever this key is pressed.
Apparently the best way is to use a low-level hook, since RegisterHotkey doesn't intercept the key.

Get notification on Ctrl+Alt+Del

I know there is no way to block or ignore ctrl+Alt+Del within a program. But thats not what I want. Is there a way to only be notified if it WAS pressed? No interaction required, only notification.
Thank you!
I'm not sure why you'd want to do this, and I have a suspicion there's probably a better and cleaner way to accomplish your ultimate goal, but...
Off the top of my head, I would run a timer in the background of your application, and each time the timer fires, check to see if the Ctrl , Alt , and Delete keys were pressed. To do that, you'll have to use GetAsyncKeyState from user32.dll. I'd give you a code sample, but I'm not sure what language you're using. Play around with the interval for the timer to see what it needs to be to balance performance, yet still work.
Doesn't seem that there is an easy way to get a SAS notification, all articles I've found dealt with replacing GINA.
You might want to take a look at these:
Customizing GINA, Part 1
Customizing GINA, Part 2
C++ Q&A Typename, Disabling Keys in Windows XP with TrapKeys
If you only want to find out whether the user has locked his workstation, you should take a look at WTSRegisterSessionNotification in conjunction with WM_WTSESSION_CHANGE.

Resources