1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2017 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _HI_GUI_GTKEYBOARDDRIVER_H_ 23 #define _HI_GUI_GTKEYBOARDDRIVER_H_ 24 25 #include <QMap> 26 27 #include "GTGlobals.h" 28 29 #ifdef _WIN32 30 # include <windows.h> 31 #endif 32 33 #define ADD_KEY(name, code) insert(name, code) 34 35 namespace HI { 36 /*! 37 * \brief The base class for keyboard's actions imitation 38 * 39 * Example: 40 * \code {.cpp} 41 * GTKeyboardDriver::keyClick( 'A'); // print 'a' 42 * GTKeyboardDriver::keyClick( 'a'); // print 'a' 43 * 44 * GTKeyboardDriver::keyClick( 'a', GTKeyboardDriver::key[Qt::Key_Shift]); // print 'A' 45 * GTKeyboardDriver::keyClick( 'a', GTKeyboardDriver::key[Qt::Key_Shift]); // print 'A' 46 * //case in ["..."] does not matter 47 * 48 * GTKeyboardDriver::keySequence("ThIs Is a TeSt StRiNg"); // print "ThIs Is a TeSt StRiNg" 49 * //i.e. case sensitive 50 * \endcode 51 */ 52 class HI_EXPORT GTKeyboardDriver { 53 public: 54 // 55 // fails if key == 0 56 // Linux: fails if there is an opening X display error 57 58 static bool keyClick(char key, Qt::KeyboardModifiers = Qt::NoModifier, bool waitForMainThread = true); 59 static bool keyClick(Qt::Key, Qt::KeyboardModifiers = Qt::NoModifier, bool waitForMainThread = true); 60 static bool keySequence(const QString &str, Qt::KeyboardModifiers = Qt::NoModifier); 61 62 static bool keyPress(char key, Qt::KeyboardModifiers = Qt::NoModifier); 63 static bool keyRelease(char key, Qt::KeyboardModifiers = Qt::NoModifier); 64 static bool keyPress(Qt::Key, Qt::KeyboardModifiers = Qt::NoModifier); 65 static bool keyRelease(Qt::Key, Qt::KeyboardModifiers = Qt::NoModifier); 66 67 class HI_EXPORT keys : private QMap<Qt::Key, int> { 68 public: 69 keys(); 70 int operator[](const Qt::Key &key) const; 71 }; 72 73 static keys key; 74 75 /** Maps Shift, Alt, Control and Meta modifiers to the corresponding key codes. */ 76 static QList<Qt::Key> modifiersToKeys(Qt::KeyboardModifiers m); 77 }; 78 79 } // namespace HI 80 81 #endif 82