/** * Copyright 2018 Albert Vaca Cintora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "windowsremoteinput.h" #include #include WindowsRemoteInput::WindowsRemoteInput(QObject* parent) : AbstractRemoteInput(parent) { } bool WindowsRemoteInput::handlePacket(const NetworkPacket& np) { float dx = np.get(QStringLiteral("dx"), 0); float dy = np.get(QStringLiteral("dy"), 0); bool isSingleClick = np.get(QStringLiteral("singleclick"), false); bool isDoubleClick = np.get(QStringLiteral("doubleclick"), false); bool isMiddleClick = np.get(QStringLiteral("middleclick"), false); bool isRightClick = np.get(QStringLiteral("rightclick"), false); bool isSingleHold = np.get(QStringLiteral("singlehold"), false); bool isSingleRelease = np.get(QStringLiteral("singlerelease"), false); bool isScroll = np.get(QStringLiteral("scroll"), false); QString key = np.get(QStringLiteral("key"), QLatin1String("")); int specialKey = np.get(QStringLiteral("specialKey"), 0); if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isScroll || !key.isEmpty() || specialKey) { INPUT input={0}; input.type = INPUT_MOUSE; if (isSingleClick) { input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_LEFTUP; ::SendInput(1,&input,sizeof(INPUT)); } else if (isDoubleClick) { input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_LEFTUP; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_LEFTUP; ::SendInput(1,&input,sizeof(INPUT)); } else if (isMiddleClick) { input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; ::SendInput(1,&input,sizeof(INPUT)); } else if (isRightClick) { input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN; ::SendInput(1,&input,sizeof(INPUT)); input.mi.dwFlags = MOUSEEVENTF_RIGHTUP; ::SendInput(1,&input,sizeof(INPUT)); } else if (isSingleHold){ input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; ::SendInput(1,&input,sizeof(INPUT)); } else if (isSingleRelease){ input.mi.dwFlags = MOUSEEVENTF_LEFTUP; ::SendInput(1,&input,sizeof(INPUT)); } else if (isScroll) { input.mi.dwFlags = MOUSEEVENTF_WHEEL; input.mi.mouseData = dy; ::SendInput(1,&input,sizeof(INPUT)); //TODO: Keyboard input support /* } else if (!key.isEmpty() || specialKey) { bool ctrl = np.get(QStringLiteral("ctrl"), false); bool alt = np.get(QStringLiteral("alt"), false); bool shift = np.get(QStringLiteral("shift"), false); if (ctrl) XTestFakeKeyEvent (display, XKeysymToKeycode(display, XK_Control_L), True, 0); if (alt) XTestFakeKeyEvent (display, XKeysymToKeycode(display, XK_Alt_L), True, 0); if (shift) XTestFakeKeyEvent (display, XKeysymToKeycode(display, XK_Shift_L), True, 0); if (specialKey) { if (specialKey >= (int)arraySize(SpecialKeysMap)) { qWarning() << "Unsupported special key identifier"; return false; } int keycode = XKeysymToKeycode(display, SpecialKeysMap[specialKey]); XTestFakeKeyEvent (display, keycode, True, 0); XTestFakeKeyEvent (display, keycode, False, 0); } else { if (!m_fakekey) { m_fakekey = fakekey_init(display); if (!m_fakekey) { qWarning() << "Failed to initialize libfakekey"; return false; } } //We use fakekey here instead of XTest (above) because it can handle utf characters instead of keycodes. for (int i=0;i