Format every single file using .clang-format
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
#include "KeyboardInputDummy.h"
|
||||
|
||||
// Used to get the compiler to shut up about C4100: unreferenced formal parameter.
|
||||
// The cast is to get GCC to shut up about it.
|
||||
#define UNREFERENCED_PARAMETER(P) static_cast<void>((P))
|
||||
// Used to get the compiler to shut up about C4100: unreferenced formal
|
||||
// parameter. The cast is to get GCC to shut up about it.
|
||||
#define UNREFERENCED_PARAMETER( P ) static_cast<void>( ( P ) )
|
||||
|
||||
namespace advsettings {
|
||||
|
||||
void KeyboardInputDummy::sendKeyboardInput(QString input)
|
||||
namespace advsettings
|
||||
{
|
||||
void KeyboardInputDummy::sendKeyboardInput( QString input )
|
||||
{
|
||||
// noop
|
||||
UNREFERENCED_PARAMETER(input);
|
||||
UNREFERENCED_PARAMETER( input );
|
||||
}
|
||||
|
||||
void KeyboardInputDummy::sendKeyboardEnter()
|
||||
@@ -17,10 +17,10 @@ void KeyboardInputDummy::sendKeyboardEnter()
|
||||
// noop
|
||||
}
|
||||
|
||||
void KeyboardInputDummy::sendKeyboardBackspace(int count)
|
||||
void KeyboardInputDummy::sendKeyboardBackspace( int count )
|
||||
{
|
||||
// noop
|
||||
UNREFERENCED_PARAMETER(count);
|
||||
UNREFERENCED_PARAMETER( count );
|
||||
}
|
||||
|
||||
void KeyboardInputDummy::sendKeyboardAltTab()
|
||||
@@ -28,4 +28,4 @@ void KeyboardInputDummy::sendKeyboardAltTab()
|
||||
// noop
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace advsettings
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
#include "../KeyboardInput.h"
|
||||
|
||||
// application namespace
|
||||
namespace advsettings {
|
||||
|
||||
namespace advsettings
|
||||
{
|
||||
class KeyboardInputDummy : public KeyboardInput
|
||||
{
|
||||
public:
|
||||
virtual void sendKeyboardInput(QString input) override;
|
||||
virtual void sendKeyboardInput( QString input ) override;
|
||||
virtual void sendKeyboardEnter() override;
|
||||
virtual void sendKeyboardBackspace(int count) override;
|
||||
virtual void sendKeyboardBackspace( int count ) override;
|
||||
virtual void sendKeyboardAltTab() override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace advsettings
|
||||
|
||||
#endif // KEYBOARDINPUTDUMMY_H
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
#include <Windows.h>
|
||||
#include "../../logging.h"
|
||||
|
||||
namespace advsettings {
|
||||
|
||||
void fillKiStruct(INPUT& ip, WORD scanCode, bool keyup) {
|
||||
namespace advsettings
|
||||
{
|
||||
void fillKiStruct( INPUT& ip, WORD scanCode, bool keyup )
|
||||
{
|
||||
ip.type = INPUT_KEYBOARD;
|
||||
ip.ki.wVk = scanCode;
|
||||
if (keyup) {
|
||||
if ( keyup )
|
||||
{
|
||||
ip.ki.dwFlags = KEYEVENTF_KEYUP;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ip.ki.dwFlags = 0;
|
||||
}
|
||||
ip.ki.wScan = 0;
|
||||
@@ -17,78 +21,103 @@ void fillKiStruct(INPUT& ip, WORD scanCode, bool keyup) {
|
||||
ip.ki.time = 0;
|
||||
};
|
||||
|
||||
void sendKeyboardInputRaw(int inputCount, LPINPUT input) {
|
||||
if ((inputCount > 0) && !SendInput(static_cast<UINT>(inputCount), input, sizeof(INPUT))) {
|
||||
char *err;
|
||||
void sendKeyboardInputRaw( int inputCount, LPINPUT input )
|
||||
{
|
||||
if ( ( inputCount > 0 )
|
||||
&& !SendInput(
|
||||
static_cast<UINT>( inputCount ), input, sizeof( INPUT ) ) )
|
||||
{
|
||||
char* err;
|
||||
auto errCode = GetLastError();
|
||||
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
nullptr,
|
||||
errCode,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
|
||||
reinterpret_cast<LPTSTR>(&err),
|
||||
0,
|
||||
nullptr)){
|
||||
LOG(ERROR) << "Error calling SendInput(): Could not get error message (" << errCode << ")";
|
||||
} else {
|
||||
LOG(ERROR) << "Error calling SendInput(): " << err;
|
||||
if ( !FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
nullptr,
|
||||
errCode,
|
||||
MAKELANGID( LANG_NEUTRAL,
|
||||
SUBLANG_DEFAULT ), // default language
|
||||
reinterpret_cast<LPTSTR>( &err ),
|
||||
0,
|
||||
nullptr ) )
|
||||
{
|
||||
LOG( ERROR )
|
||||
<< "Error calling SendInput(): Could not get error message ("
|
||||
<< errCode << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( ERROR ) << "Error calling SendInput(): " << err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInputWindows::sendKeyboardInput(QString input)
|
||||
void KeyboardInputWindows::sendKeyboardInput( QString input )
|
||||
{
|
||||
int len = input.length();
|
||||
if (len > 0) {
|
||||
LPINPUT ips = new INPUT[static_cast<unsigned int>(len) * 5 + 3];
|
||||
if ( len > 0 )
|
||||
{
|
||||
LPINPUT ips = new INPUT[static_cast<unsigned int>( len ) * 5 + 3];
|
||||
int ii = 0;
|
||||
bool shiftPressed = false;
|
||||
bool ctrlPressed = false;
|
||||
bool altPressed = false;
|
||||
for (int i = 0; i < len; i++) {
|
||||
short tmp = VkKeyScan(input.at(i).toLatin1());
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
short tmp = VkKeyScan( input.at( i ).toLatin1() );
|
||||
WORD c = tmp & 0xFF;
|
||||
short shiftState = tmp >> 8;
|
||||
bool isShift = shiftState & 1;
|
||||
bool isCtrl = shiftState & 2;
|
||||
bool isAlt = shiftState & 4;
|
||||
if (isShift && !shiftPressed) {
|
||||
fillKiStruct(ips[ii++], VK_SHIFT, false);
|
||||
if ( isShift && !shiftPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_SHIFT, false );
|
||||
shiftPressed = true;
|
||||
} else if (!isShift && shiftPressed) {
|
||||
fillKiStruct(ips[ii++], VK_SHIFT, true);
|
||||
}
|
||||
else if ( !isShift && shiftPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_SHIFT, true );
|
||||
shiftPressed = false;
|
||||
}
|
||||
if (isCtrl && !ctrlPressed) {
|
||||
fillKiStruct(ips[ii++], VK_CONTROL, false);
|
||||
if ( isCtrl && !ctrlPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_CONTROL, false );
|
||||
ctrlPressed = true;
|
||||
} else if (!isCtrl && ctrlPressed) {
|
||||
fillKiStruct(ips[ii++], VK_CONTROL, true);
|
||||
}
|
||||
else if ( !isCtrl && ctrlPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_CONTROL, true );
|
||||
ctrlPressed = false;
|
||||
}
|
||||
if (isAlt && !altPressed) {
|
||||
fillKiStruct(ips[ii++], VK_MENU, false);
|
||||
if ( isAlt && !altPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_MENU, false );
|
||||
altPressed = true;
|
||||
} else if (!isAlt && altPressed) {
|
||||
fillKiStruct(ips[ii++], VK_MENU, true);
|
||||
}
|
||||
else if ( !isAlt && altPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_MENU, true );
|
||||
altPressed = false;
|
||||
}
|
||||
fillKiStruct(ips[ii++], c, false);
|
||||
fillKiStruct(ips[ii++], c, true);
|
||||
fillKiStruct( ips[ii++], c, false );
|
||||
fillKiStruct( ips[ii++], c, true );
|
||||
}
|
||||
if (shiftPressed) {
|
||||
fillKiStruct(ips[ii++], VK_SHIFT, true);
|
||||
if ( shiftPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_SHIFT, true );
|
||||
shiftPressed = false;
|
||||
}
|
||||
if (ctrlPressed) {
|
||||
fillKiStruct(ips[ii++], VK_CONTROL, true);
|
||||
if ( ctrlPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_CONTROL, true );
|
||||
ctrlPressed = false;
|
||||
}
|
||||
if (altPressed) {
|
||||
fillKiStruct(ips[ii++], VK_MENU, true);
|
||||
if ( altPressed )
|
||||
{
|
||||
fillKiStruct( ips[ii++], VK_MENU, true );
|
||||
altPressed = false;
|
||||
}
|
||||
|
||||
sendKeyboardInputRaw(ii, ips);
|
||||
sendKeyboardInputRaw( ii, ips );
|
||||
delete[] ips;
|
||||
}
|
||||
}
|
||||
@@ -96,24 +125,26 @@ void KeyboardInputWindows::sendKeyboardInput(QString input)
|
||||
void KeyboardInputWindows::sendKeyboardEnter()
|
||||
{
|
||||
LPINPUT ips = new INPUT[2];
|
||||
fillKiStruct(ips[0], VK_RETURN, false);
|
||||
fillKiStruct(ips[1], VK_RETURN, true);
|
||||
fillKiStruct( ips[0], VK_RETURN, false );
|
||||
fillKiStruct( ips[1], VK_RETURN, true );
|
||||
|
||||
sendKeyboardInputRaw(2, ips);
|
||||
sendKeyboardInputRaw( 2, ips );
|
||||
delete[] ips;
|
||||
}
|
||||
|
||||
void KeyboardInputWindows::sendKeyboardBackspace(int count)
|
||||
void KeyboardInputWindows::sendKeyboardBackspace( int count )
|
||||
{
|
||||
if (count > 0) {
|
||||
if ( count > 0 )
|
||||
{
|
||||
// We ensure that count is nonnegative, therefore safe cast.
|
||||
LPINPUT ips = new INPUT[static_cast<unsigned int>(count) * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
fillKiStruct(ips[2 * i], VK_BACK, false);
|
||||
fillKiStruct(ips[2 * i + 1], VK_BACK, true);
|
||||
LPINPUT ips = new INPUT[static_cast<unsigned int>( count ) * 2];
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
fillKiStruct( ips[2 * i], VK_BACK, false );
|
||||
fillKiStruct( ips[2 * i + 1], VK_BACK, true );
|
||||
}
|
||||
|
||||
sendKeyboardInputRaw(count * 2, ips);
|
||||
sendKeyboardInputRaw( count * 2, ips );
|
||||
delete[] ips;
|
||||
}
|
||||
}
|
||||
@@ -122,13 +153,13 @@ void KeyboardInputWindows::sendKeyboardAltTab()
|
||||
{
|
||||
LPINPUT ips = new INPUT[4];
|
||||
// VK_MENU is alt
|
||||
fillKiStruct(ips[0], VK_MENU, false);
|
||||
fillKiStruct(ips[1], VK_TAB, false);
|
||||
fillKiStruct(ips[2], VK_TAB, true);
|
||||
fillKiStruct(ips[3], VK_MENU, true);
|
||||
fillKiStruct( ips[0], VK_MENU, false );
|
||||
fillKiStruct( ips[1], VK_TAB, false );
|
||||
fillKiStruct( ips[2], VK_TAB, true );
|
||||
fillKiStruct( ips[3], VK_MENU, true );
|
||||
|
||||
sendKeyboardInputRaw(4, ips);
|
||||
sendKeyboardInputRaw( 4, ips );
|
||||
delete[] ips;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace advsettings
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
#include "../KeyboardInput.h"
|
||||
|
||||
// application namespace
|
||||
namespace advsettings {
|
||||
|
||||
namespace advsettings
|
||||
{
|
||||
class KeyboardInputWindows : public KeyboardInput
|
||||
{
|
||||
public:
|
||||
virtual void sendKeyboardInput(QString input) override;
|
||||
virtual void sendKeyboardInput( QString input ) override;
|
||||
virtual void sendKeyboardEnter() override;
|
||||
virtual void sendKeyboardBackspace(int count) override;
|
||||
virtual void sendKeyboardBackspace( int count ) override;
|
||||
virtual void sendKeyboardAltTab() override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace advsettings
|
||||
|
||||
#endif // KEYBOARDINPUTWINDOWS_H
|
||||
|
||||
Reference in New Issue
Block a user