uLib  User mode C/C++ extended API library for Win32 programmers.
Keyboard and Mouse Event Emulation

Module Description

Easy to use keyboard and mouse emulation.
#include <uLib/InputEmu.h>

This module contains API's that simplify the emulation of keyboard and mouse events.
These are useful when creating 'macro' functions, e.g. for automation..

Macros

#define MAKE_HOTKEY(key, flags)   (WORD)(((flags) << 8) | key)
 

Enumerations

enum  MOUSEKEY { LBUTTON = _BV(0), MBUTTON = _BV(1), RBUTTON = _BV(2) }
 

Functions

void MakeKeyInput (INPUT *Inp, WORD vKey, DWORD Flags)
 
UINT SendKeyInput (WORD vKey, DWORD Flags=0)
 
bool SendKeyPress (WORD vKey)
 
bool SendHotKey (WORD Hotkey)
 
void MakeMouseInput (INPUT *Inp, LONG dx, LONG dy, LONG data, DWORD Flags)
 
UINT SendMouseInput (LONG dx, LONG dy, LONG data, DWORD Flags)
 
bool SendMouseClick (MOUSEKEY Key)
 

Macro Definition Documentation

◆ MAKE_HOTKEY

#define MAKE_HOTKEY (   key,
  flags 
)    (WORD)(((flags) << 8) | key)

Definition at line 23 of file InputEmu.h.

Enumeration Type Documentation

◆ MOUSEKEY

enum MOUSEKEY

Key flags for SendMouseClick().

Enumerator
LBUTTON 

Left mouse button.

MBUTTON 

Middle mouse button.

RBUTTON 

Right mouse button.

Definition at line 76 of file InputEmu.h.

Function Documentation

◆ MakeKeyInput()

void MakeKeyInput ( INPUT *  Inp,
WORD  vKey,
DWORD  Flags 
)

Initialize INPUT for keyboard emulation with SendInput.
If vKey > 254, MapVirtualKey is used to map the scancode to a virtual keycode.

Parameters
[out]InpPointer to an INPUT struct to initialize.
[in]vKeyVirtual keycode (VK_nn) or scancode (>254) of the key to emulate.
[in]FlagsKEYEVENTF_nn flags (KEYEVENTF_SCANCODE is added automatically if vKey > 254).

Definition at line 15 of file InputEmu.cpp.

◆ SendKeyInput()

UINT SendKeyInput ( WORD  vKey,
DWORD  Flags = 0 
)

Send a single key, press or release.
See MakeKeyInput for parameter explanations.

Note: I seems someone at MS has chosen to reinterpret the meaning of KEYEVENTF_KEYUP
to mean both key down and key up. This can be observed on Windows 7 where apps recieve
two of the specified vKey in a row, when using the normal procedure of sending one INPUT
struct for key down and one for key up.
However, the quirk does not occur for emulated shift keys.. Go figure.

See also
[MSDN} SendInput().

Definition at line 26 of file InputEmu.cpp.

◆ SendKeyPress()

bool SendKeyPress ( WORD  vKey)

Send a single key, press and release.
See SendKeyInput() for details.

Definition at line 34 of file InputEmu.cpp.

◆ SendHotKey()

bool SendHotKey ( WORD  Hotkey)

Send a standard ComCtl32 HotKey (press and release).

Definition at line 43 of file InputEmu.cpp.

◆ MakeMouseInput()

void MakeMouseInput ( INPUT *  Inp,
LONG  dx,
LONG  dy,
LONG  data,
DWORD  Flags 
)

Initialize INPUT for mouse emulation with SendInput.

Parameters
[out]InpPointer to an INPUT struct to initialize.
[in]dx,dyScreen position of the emulated mouse event.
[in]dataDependent on Flags.. E.g wheel movement if Flags contain MOUSEEVENTF_WHEEL.
[in]FlagsMOUSEEVENTF_nn flags.
See also
[MSDN] MOUSEINPUT

Definition at line 108 of file InputEmu.cpp.

◆ SendMouseInput()

UINT SendMouseInput ( LONG  dx,
LONG  dy,
LONG  data,
DWORD  Flags 
)

Send a single mouse event.
See MakeMouseInput() for parameter explanations.
See also [MSDN} SendInput().

Definition at line 119 of file InputEmu.cpp.

◆ SendMouseClick()

bool SendMouseClick ( MOUSEKEY  Key)

Send a single mouse click/chord (press and release).

Definition at line 128 of file InputEmu.cpp.