Results 1 to 12 of 12

Thread: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    16
    Thanks
    4
    Qt products
    Qt4

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    Quote Originally Posted by high_flyer View Post
    Again, TCHAR is a windows type.
    You need to include the correct windows header for that type.
    Did you try including windows.h?
    Yes, I've included it. There is an include directive in sendkeys.h :
    Qt Code:
    1. #include <windows.h>
    2. #include <tchar.h>
    To copy to clipboard, switch view to plain text mode 
    I also want to share my Qt program which doesn't work because of that error I've mentioned. please take a look at this project and let me know if I can change something which helps me run the program.
    The purpose of this program is running notepad using Sendkeys class:
    QtSendKey.zip
    You can read more information about the Sendkeys class here.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    Show the line of code that generates the error. If all you need is to call WinApi function that expects TCHAR *, you can use the L"" macro:
    Qt Code:
    1. HRESULT someWinApiMethod( TCHAR * string );
    2. //...
    3. someWinApiMethod(L"a wide unicode string constant");
    To copy to clipboard, switch view to plain text mode 
    As for QStrings, you can use toWCharArray and fromWCharArray conversion methods.

  3. The following user says thank you to stampede for this useful post:

    tofighi (28th May 2011)

  4. #3
    Join Date
    May 2011
    Posts
    16
    Thanks
    4
    Qt products
    Qt4

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    Quote Originally Posted by stampede View Post
    Show the line of code that generates the error. If all you need is to call WinApi function that expects TCHAR *, you can use the L"" macro:
    Qt Code:
    1. HRESULT someWinApiMethod( TCHAR * string );
    2. //...
    3. someWinApiMethod(L"a wide unicode string constant");
    To copy to clipboard, switch view to plain text mode 
    As for QStrings, you can use toWCharArray and fromWCharArray conversion methods.
    That's a good suggestion. I convert some strings with this method and errors reduce. There are some other errors that I don't know how to solve:
    for example

    Qt Code:
    1. int cmp = _tcsnicmp(KeyNames[Middle].keyName, KeyString, _tcslen(KeyString));
    2. error: cannot convert 'TCHAR*' to 'char*' for argument '1' to 'char* strncpy(char*, const char*, size_t)'
    3.  
    4. while (*p && *p != _TXCHAR('}'))
    5. p++;
    6. error: '_TXCHAR' was not declared in this scope
    7.  
    8. _tcscpy(titleclass, WindowTitle);
    9. error: cannot convert 'TCHAR*' to 'const char*' for argument '1' to 'char* strstr(const char*, const char*)'
    To copy to clipboard, switch view to plain text mode 

    I suggest an expert, if has time, see the attached code in previous post and debug it. I'm sure it is a very useful program which can help many.

  5. #4
    Join Date
    May 2011
    Posts
    16
    Thanks
    4
    Qt products
    Qt4

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    Is it possible someone look at this again?

  6. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    error: '_TXCHAR' was not declared in this scope
    You need to include tchar.h
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #6
    Join Date
    May 2011
    Posts
    16
    Thanks
    4
    Qt products
    Qt4

    Default Re: How to trigger a hotkey or shortcut or emulate keyboard with Qt?

    Quote Originally Posted by high_flyer View Post
    You need to include tchar.h
    I did it before. Is it possible to ask you kindly download the program, and compile it to see errors? This program is very useful and I know it will help many to create HCI programs using Qt.

Similar Threads

  1. Keyboard shortcut event not received
    By D Cell in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2010, 09:52
  2. Replies: 3
    Last Post: 23rd August 2010, 10:37
  3. Additional keyboard shortcut for a menu
    By negritot in forum Qt Programming
    Replies: 5
    Last Post: 17th September 2009, 05:58
  4. Invoke QCompletion on keyboard shortcut
    By aspidites in forum Qt Programming
    Replies: 0
    Last Post: 30th August 2009, 10:32
  5. Rerouting messages for keyboard shortcut selection dialog.
    By andy.fillebrown in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 18:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.