Help with ToAscii function and keyboard hook 
Author Message
 Help with ToAscii function and keyboard hook

I am hoping to get some help with the following problem. I have hooked the
keyboard globally, and I am attempting to display the hooked output in an
edit box. Right now the following code is rudimentary, but I have one major
problem: I cannot seem to display the shift state of the characters. The
characters all show up lower case.

It was my impression that the ToAscii function would give me upper case
letters and lower case ones, depending on the ASCII code...

If anyone can help me out, I'd greatly appreciate it.

Thanks,

PJ
-------------------------------------------------------
static HWND hwndEdit;
 TCHAR szBuf[255];
 int temp = 0;
 char KeyAscii[2];
 TCHAR szBuffer[255];
 BYTE KeybdState[256];

case WM_KEYBOARDMESSAGE:
  if (GetKeyboardState (KeybdState)) {
   temp = ToAscii (wParam, lParam, KeybdState, (unsigned short *) KeyAscii,
0);
   if ((temp == 1) && ((*KeyAscii > 31) || (*KeyAscii == 13))) {
    if (*KeyAscii == 13)
     wsprintf(szBuffer, TEXT("[Enter]\r\n"));
    else
     wsprintf(szBuffer, TEXT("%s"), KeyAscii); //this line gives me only
lower case letters
   }
   else {
    temp = GetKeyNameText (lParam, szBuffer, sizeof(szBuffer));
    wsprintf(szBuf, TEXT("[%s]"), szBuffer);
   }
  }

  SetWindowText(hwndEdit, (temp == 1 ? szBuffer : szBuf));
  return 0;
-------------------------------------------------------



Sat, 10 May 2003 03:00:00 GMT  
 Help with ToAscii function and keyboard hook
Keyboard state is maintained on a per-thread basis. Global hook filter
function is executed in the context of the thread retrieving the keyboard
message. Then, I assume, you post the application-defined message to your
main program - but GetKeyboardState called from the main program does not
reflect the state of the keys like CapsLock and Shift as seen by the thread
that got keyboard message in the first place.

Why don't you call ToAscii from the hook and send a resulting Ascii code to
the main app?
--
With best wishes,
    Igor Tandetnik


Quote:
> I am hoping to get some help with the following problem. I have hooked the
> keyboard globally, and I am attempting to display the hooked output in an
> edit box. Right now the following code is rudimentary, but I have one
major
> problem: I cannot seem to display the shift state of the characters. The
> characters all show up lower case.

> It was my impression that the ToAscii function would give me upper case
> letters and lower case ones, depending on the ASCII code...

> If anyone can help me out, I'd greatly appreciate it.

> Thanks,

> PJ
> -------------------------------------------------------
> static HWND hwndEdit;
>  TCHAR szBuf[255];
>  int temp = 0;
>  char KeyAscii[2];
>  TCHAR szBuffer[255];
>  BYTE KeybdState[256];

> case WM_KEYBOARDMESSAGE:
>   if (GetKeyboardState (KeybdState)) {
>    temp = ToAscii (wParam, lParam, KeybdState, (unsigned short *)
KeyAscii,
> 0);
>    if ((temp == 1) && ((*KeyAscii > 31) || (*KeyAscii == 13))) {
>     if (*KeyAscii == 13)
>      wsprintf(szBuffer, TEXT("[Enter]\r\n"));
>     else
>      wsprintf(szBuffer, TEXT("%s"), KeyAscii); file://this line gives me
only
> lower case letters
>    }
>    else {
>     temp = GetKeyNameText (lParam, szBuffer, sizeof(szBuffer));
>     wsprintf(szBuf, TEXT("[%s]"), szBuffer);
>    }
>   }

>   SetWindowText(hwndEdit, (temp == 1 ? szBuffer : szBuf));
>   return 0;
> -------------------------------------------------------



Sat, 10 May 2003 03:00:00 GMT  
 Help with ToAscii function and keyboard hook

Try this:

GetKeyboardState (KeybdState);
KeybdState[16] = 129            // index 16 is virtualkeycode for the LEFT
SHIFT
now the function ToAsciiEx (virtualKey, Scancode, KeyboardState, buffer,
bufferlen, keyboardlayout) will retrieve always upper case chars.

mfg.
Fred.



Quote:
> I am hoping to get some help with the following problem. I have hooked the
> keyboard globally, and I am attempting to display the hooked output in an
> edit box. Right now the following code is rudimentary, but I have one
major
> problem: I cannot seem to display the shift state of the characters. The
> characters all show up lower case.

> It was my impression that the ToAscii function would give me upper case
> letters and lower case ones, depending on the ASCII code...

> If anyone can help me out, I'd greatly appreciate it.

> Thanks,

> PJ
> -------------------------------------------------------
> static HWND hwndEdit;
>  TCHAR szBuf[255];
>  int temp = 0;
>  char KeyAscii[2];
>  TCHAR szBuffer[255];
>  BYTE KeybdState[256];

> case WM_KEYBOARDMESSAGE:
>   if (GetKeyboardState (KeybdState)) {
>    temp = ToAscii (wParam, lParam, KeybdState, (unsigned short *)
KeyAscii,
> 0);
>    if ((temp == 1) && ((*KeyAscii > 31) || (*KeyAscii == 13))) {
>     if (*KeyAscii == 13)
>      wsprintf(szBuffer, TEXT("[Enter]\r\n"));
>     else
>      wsprintf(szBuffer, TEXT("%s"), KeyAscii); file://this line gives me
only
> lower case letters
>    }
>    else {
>     temp = GetKeyNameText (lParam, szBuffer, sizeof(szBuffer));
>     wsprintf(szBuf, TEXT("[%s]"), szBuffer);
>    }
>   }

>   SetWindowText(hwndEdit, (temp == 1 ? szBuffer : szBuf));
>   return 0;
> -------------------------------------------------------



Fri, 16 May 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Interesting behavior of keyboard hook function.

2. Interesting behavior of keyboard hook function.

3. Need Help On Win32 (Keyboard) Hooks

4. Please Help:Keyboard hook

5. Please Help:Keyboard hook

6. Creating system wide keyboard Hooks with c#

7. Keyboard Hook

8. My keyboard hook gets called twice.

9. Hooking/redirecting keyboard interrupt in C(++)

10. Keyboard hooks

11. Keyboard hook problem

12. keyboard hook question

 

 
Powered by phpBB® Forum Software