Re: WM_KEYDOWN, WM_CHAR and WM_KEYUP by Stoitcho
Stoitcho
Mon Oct 18 19:22:12 CDT 2004
Hi Alex,
Private means that the method is not supposed to be called even from the
derived classes. Those methods are not documented and are subject to change.
Such methods dont't have to be called.
Looking on the code of these private methods I can see that they use the
idea, that I threw in my previous post, to use SetKeyboardState. So it is
possible to be implemented even without using such a hack of calling private
methods. Anyways usign PInvoke has the drawback that the caller must have
enough permissions. The reflection has the same problem though.
--
Stoitcho Goutsev (100) [C# MVP]
"Alex Korchemniy" <AlexKorchemniy@discussions.microsoft.com> wrote in
message news:1F4FB85B-81A0-48FC-9317-1F9485F02EE8@microsoft.com...
> Yes I know that.
>
> But it is possible to use reflection to call the private methods of the
> class. Its not too 'safe' (private methods could change) but possible.
>
> If you use Reflector you can see methods like:
> - private static bool AddSimpleKey(char character, int repeat, IntPtr
> hwnd,
> int[] haveKeys, bool fStartNewChar, int cGrp)
> - private static void AddMsgsForVK(int vk, int repeat, bool altnoctrldown,
> IntPtr hwnd)
> - private static void Send(string keys, Control control, bool wait)
>
> ---
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Alex Korchemniy
>
> "Stoitcho Goutsev (100) [C# MVP]" wrote:
>
>> Hi Alex,
>>
>> SendKeys simulates keystrokes typed on the keyboard. It has no target
>> window. Whatever is the active focused window it gets the keys. It is the
>> same when you type.
>>
>>
>> --
>> Stoitcho Goutsev (100) [C# MVP]
>>
>> "Alex Korchemniy" <AlexKorchemniy@discussions.microsoft.com> wrote in
>> message news:DF0FCA55-8038-49C2-92FD-CDB114EBDDCD@microsoft.com...
>> > SendKeys class. Check out this managed way of sending keys:
>> > msdn.microsoft.com/library/en-us/cpref/
>> > html/frlrfsystemwindowsformssendkeysclasstopic.asp
>> >
>> > It works for send keys to the current window. I've ran Reflector and
>> > it
>> > looks like you can possible create a reflections hack to invoke a
>> > private
>> > method and use that to send the keys :)
>> >
>> > ---
>> > This posting is provided "AS IS" with no warranties, and confers no
>> > rights.
>> > Alex Korchemniy
>> >
>> > "Jeremy Chapman" wrote:
>> >
>> >> I am using SendMessage() to send characters to a window. After using
>> >> Microsoft Spy++ to look at window messages when I click a key, I
>> >> noticed
>> >> that the enter key sends WM_KeyDown WM_Char and WM_KeyUp but the home
>> >> key
>> >> only sends WM_KeyDown and WM_KeyUp. Is there some rule I can use to
>> >> tell
>> >> if
>> >> I should send the WM_Char or not?
>> >>
>> >>
>> >>
>>
>>
>>