Results 1 to 3 of 3

Thread: Virtual Key microsoft

  1. #1
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Virtual Key microsoft

    I am trying to show my virtual keys:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Code:
    Qt Code:
    1. switch (wParam)
    2. {
    3. case VK_CONTROL:
    4.  
    5. qDebug() << "prueba";
    6.  
    7. break;
    8.  
    9. default:
    10. break;
    11. }
    To copy to clipboard, switch view to plain text mode 
    I think i am doing some wrong? It's because i want learn more about virtual keys for one virtual keyboard that i will do. Thx

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Virtual Key microsoft

    I think we need a little more context, e.g. what is wParam, how is this code called, ...

    Ginsengelf

    edit: also helpful might be what happens and why you think it's wrong...

  3. #3
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Virtual Key microsoft

    Basically doesnt capture ctrl when i press ctrl show me:
    "\u0015"

    Hi! i will try to explain and take all details first.
    It's basically the LRESULT CALLBACK Function where i will put all events showing and all things so i do this:
    Qt Code:
    1. LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
    2. {
    3.  
    4.  
    5. //WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
    6. //LPARAM is the key information
    7. // if( wParam == WM_KEYDOWN )
    8. //qDebug() << "Key Pressed!";
    9.  
    10. //Get the key information
    11.  
    12. KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
    13.  
    14. wchar_t buffer[5];
    15.  
    16. //get the keyboard state
    17. BYTE keyboard_state[256];
    18. GetKeyboardState(keyboard_state);
    19. UpdateKeyState(keyboard_state, VK_SHIFT);
    20. UpdateKeyState(keyboard_state, VK_CAPITAL);
    21. UpdateKeyState(keyboard_state, VK_CONTROL);
    22. UpdateKeyState(keyboard_state, VK_MENU);
    23.  
    24. //Get Keyboard Layout
    25. HKL keyboard_layout = GetKeyboardLayout(0);
    26.  
    27. //Get the name
    28. char lpszName[0x100] = {0};
    29.  
    30. DWORD dwMsg = 1;
    31. dwMsg += cKey.scanCode << 16;
    32. dwMsg += cKey.flags << 24;
    33.  
    34. int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
    35. //try to convert the key info
    36. int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
    37. buffer[4] = L'\0';
    38. QString num = QString::fromUtf16((ushort*)buffer);
    39. // Print the output
    40. QString s = QString::fromUtf16((ushort*)buffer);
    41. if( wParam == WM_KEYDOWN){
    42. //qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
    43. Write(mFilename,s);
    44. qDebug() << s;
    45.  
    46.  
    47. }
    48.  
    49. if (wParam == WM_KEYDOWN)
    50. {
    51. qDebug() << "hola";
    52. switch (wParam)
    53. {
    54. case VK_RETURN:
    55.  
    56. qDebug() << "prueba";
    57.  
    58. break;
    59.  
    60. default:
    61. break;
    62. }
    63. }
    64. return CallNextHookEx(hHook, nCode, wParam, lParam);
    65.  
    66.  
    67. }
    To copy to clipboard, switch view to plain text mode 
    Obviously i can do with keypress but the events dont capture only show me for example when i use ctrl u
    "\u0004"....

    If someone can help and need to check more about this i can put one example and maybe can help to solve this issue.

    All code:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QDebug>
    3. #include <QTime>
    4. #include <QChar>
    5. #include <iostream>
    6. #include <QFile>
    7. #include <QString>
    8. #include <Windows.h>
    9. #include <QTextStream>
    10. #pragma comment(lib,"user32.lib")
    11. #include "Winuser.h"
    12. HHOOK hHook = NULL;
    13.  
    14. using namespace std;
    15.  
    16.  
    17.  
    18. void Write(QString Filename, QString s)
    19. {
    20. QFile mFile(Filename);
    21. if(!mFile.open(QFile::WriteOnly | QIODevice::Text | QIODevice::Append))
    22. {
    23. //error
    24. }
    25. QTextStream out(&mFile);
    26.  
    27.  
    28. out << s ;
    29. mFile.flush();
    30. mFile.close();
    31.  
    32. }
    33.  
    34. void UpdateKeyState(BYTE *keystate, int keycode)
    35. {
    36. keystate[keycode] = GetKeyState(keycode);
    37. }
    38.  
    39. LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
    40. {
    41. QString mFilename = "C:/Users/moh/Desktop/log.txt";
    42.  
    43. //WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
    44. //LPARAM is the key information
    45. // if( wParam == WM_KEYDOWN )
    46. //qDebug() << "Key Pressed!";
    47.  
    48. //Get the key information
    49.  
    50. KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
    51.  
    52. wchar_t buffer[5];
    53.  
    54. //get the keyboard state
    55. BYTE keyboard_state[256];
    56.  
    57.  
    58. GetKeyboardState(keyboard_state);
    59. UpdateKeyState(keyboard_state, VK_SHIFT);
    60. UpdateKeyState(keyboard_state, VK_CAPITAL);
    61. UpdateKeyState(keyboard_state, VK_CONTROL);
    62. UpdateKeyState(keyboard_state, VK_MENU);
    63.  
    64. //Get Keyboard Layout
    65. HKL keyboard_layout = GetKeyboardLayout(0);
    66.  
    67. //Get the name
    68. char lpszName[0x100] = {0};
    69.  
    70. DWORD dwMsg = 1;
    71. dwMsg += cKey.scanCode << 16;
    72. dwMsg += cKey.flags << 24;
    73.  
    74. int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
    75. //try to convert the key info
    76. int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
    77. buffer[4] = L'\0';
    78. //qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
    79. QString num = QString::fromUtf16((ushort*)buffer);
    80. // Print the output
    81. QString s = QString::fromUtf16((ushort*)buffer);
    82. // int cod = cKey.vkCode;
    83. //QString s = QString::number(cod);
    84. //qDebug() << cKey.vkCode;
    85. if( wParam == WM_SYSKEYDOWN ){
    86. switch (wParam)
    87. {
    88. case VK_RETURN:
    89.  
    90. qDebug() << "prueba";
    91.  
    92. break;
    93.  
    94. default:
    95. qDebug() << "prueba";
    96. }
    97. }
    98. if( wParam == WM_KEYDOWN && cKey.vkCode>31 ){
    99. //qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
    100. //Write(mFilename,s);
    101. qDebug() << s;
    102.  
    103.  
    104. }
    105.  
    106. if( cKey.vkCode == 8){
    107. Write("","");
    108. }
    109. if( cKey.vkCode == 13){
    110. Write("","\n");
    111. }
    112.  
    113.  
    114.  
    115. return CallNextHookEx(hHook, nCode, wParam, lParam);
    116.  
    117.  
    118. }
    119.  
    120. int main(int argc, char *argv[])
    121. {
    122.  
    123. QCoreApplication a(argc, argv);
    124. hHook = SetWindowsHookEx(WH_KEYBOARD_LL, MyLowLevelKeyBoardProc, NULL,0);
    125. if(hHook == NULL){
    126. qDebug() << "error";
    127. }
    128.  
    129. /*
    130.   if(!ap.exists()){
    131.   qDebug() << "El archivo seleccionado no existe";
    132.   return 1;
    133.   }
    134.   ap.open(QIODevice::WriteOnly | QIODevice::Text);
    135.   if (!ap.isOpen()){
    136.   qDebug() << "El archivo no se ha podido abrir";
    137.   return 2;
    138.   }
    139.   //contenido = ap.readAll();
    140.   ap.write(contenido);
    141.   ap.flush();
    142.   ap.close();
    143. */
    144.  
    145. return a.exec();
    146. }
    To copy to clipboard, switch view to plain text mode 

    Any help is good received for learning!
    Last edited by davinciomare; 11th October 2016 at 18:48.

Similar Threads

  1. Replies: 10
    Last Post: 5th August 2013, 13:16
  2. I'm interested to buy/use QT. What I need from microsoft ?
    By peppe in forum Installation and Deployment
    Replies: 2
    Last Post: 20th October 2011, 22:42
  3. Qt is going to be slaughtered by Microsoft
    By genjix in forum General Discussion
    Replies: 1
    Last Post: 13th February 2011, 06:53
  4. How to use Microsoft COM interfaces in QT?
    By luochen601 in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2010, 05:22
  5. Qt4.3.2 and Microsoft SDK
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2008, 15:38

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.