Click to See Complete Forum and Search --> : send shift alt ctrl to edit control


michal_
February 1st, 2005, 06:40 AM
Hi All

i need to send various combination of keys like SHIFT+a, ALT+a, CTRL+c etc to edit control, but problem is that this edit control is inactive, hasnt got focus and mustn't receive focus so function keybd_event or sendinput i can't use, i try using following code for example for shift:

PostMessage(hEdit,WM_KEYDOWN,VK_SHIFT,MapVirtualKey(VK_SHIFT,0) | 0x00000001);
PostMessage(hEdit,WM_CHAR,'a',1);
PostMessage(hEdit,WM_KEYUP,VK_SHIFT,MapVirtualKey(VK_SHIFT,0) | 0xC0000001);

but i still have small a, but in this case i should get big one
i try also something like this

char a[256];
GetKeyboardState(a);
a[VK_SHIFT] |= 0x80;
SetKeyboardState(a);

SendMessage(hEdit,WM_CHAR,'a',1);

a[VK_SHIFT] &= 0x7F;
SetKeyboardState(a);

but it still doesn't work, i need solution which works like sendinput or keybd_event but can send keys to control which dont have focus and cant received it, any suggestion??? i will be gratefull

Greats
Michal

NoHero
February 1st, 2005, 10:08 AM
Why not sending a big A? A big A indicitates that the shift key should be pressed. If the shift key is pressed and you receive a small a that only indicates that the capital lock is enabled.


PostMessage(hEdit,WM_KEYDOWN,VK_SHIFT,MapVirtualKey(VK_SHIFT,0) | 0x00000001);
PostMessage(hEdit,WM_CHAR,'A',1);
PostMessage(hEdit,WM_KEYUP,VK_SHIFT,MapVirtualKey(VK_SHIFT,0) | 0xC0000001);

michal_
February 1st, 2005, 01:23 PM
i cant do this in that way because i only know that which keys i must simulate in my example press of shift and letter 'a',but i have written that i need solution for SHIFT, ALT, CTRL, your solution is ostensibly "good" for shift but how do you solve press ALT key plus letter 'a'?? i cant obtain what characted we receive if user press this sequence of keys, because it cant be keyboard language dependent character, so your solution is not good for me, we can imagine edit control that for pressing keys SHIFT+'a' dont display 'A' but do 'xx' action and i want to get this 'xxx' action too, so someone else have any idea???:)

greats
michal

NoHero
February 1st, 2005, 01:26 PM
i cant do this in that way because i only know that which keys i must simulate in my example press of shift and letter 'a',but i have written that i need solution for SHIFT, ALT, CTRL, your solution is ostensibly "good" for shift but how do you solve press ALT key plus letter 'a'?? i cant obtain what characted we receive if user press this sequence of keys, because it cant be keyboard language dependent character, so your solution is not good for me, we can imagine edit control that for pressing keys SHIFT+'a' dont display 'A' but do 'xx' action and i want to get this 'xxx' action too, so someone else have any idea???:)

This clarifies your need. In this case you should search the forums for 'SendInput()' and/or 'keybd_event' and I am sure you will find several threads refering and giving solution to this problem. Just take a look at the current page of the WinAPI forum thread overview, and you will find at least one.

michal_
February 1st, 2005, 05:55 PM
i know sendinput and keybd_event function, but this functions only works when you set focus to control which should receive keys, but i have written that my edit control haven't got focus and mustn't receive it ever, so i cant use it:|

greats
michal