Article View: borland.public.cppbuilder.nativeapi
Article #12621Re: Simulating that a key has been pressed
From: Bob Gonder
Date: Sun, 23 Nov 2003 16:58
Date: Sun, 23 Nov 2003 16:58
84 lines
3873 bytes
3873 bytes
Feico wrote:
>
>__declspec (dllexport) LRESULT CALLBACK Hook
> (INT nCode, WPARAM wParam, LPARAM lParam)
>{
> KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
This is a low-level-hook?
So, your are using WH_KEYBOARD_LL to set this up?
> if (nCode == HC_ACTION)
> { WPARAM wp;
> LPARAM lp;
> if( (pkbhs->flags & 128)==0)
> {
> wp='A';
> lp=1;
> SendMessage(GetForegroundWindow(), WM_KEYDOWN, wp, lp);
Probably get in trouble for using SendMessage in a low level hook. If
you don't return quickly, Win will continue sending the original hook
message to the next hook, and then the app. Use the non-blocking
PostMessage() instead.
> }
> }
> return CallNextHookEx (hKeyboardHook, nCode, wParam, lParam);
>}
From what I remember of your past messages, you want to something like
this:
#define Key_i VK_I
#define Key_e VK_E
bool last_was_i = false;
hook(INT nCode, WPARAM wParam, LPARAM lParam)
{
if( (nCode == HC_ACTION) && (wParam == WM_KEYDOWN) )
{
/* check the injected flag so we don't process our own keys */
/* ignore Alt-keys (ALT-i-e is ok) */
if( 0 == (pkbhs->flags & (LLKHF_INJECTED|LLKHF_ALTDOWN) ) )
{ if( pkbhs->vkCode == Key_i )
{ last_was_i = true;
return CallNextHookEx (hKeyboardHook, nCode,
wParam, lParam);
};
if( last_was_i )
{ last_was_i = false;
if( pkbhs->vkCode == Key_e )
{ pushkey(backspace);
pushkey('e');
pushkey('i');
return 1; /* throw away this key */
}; }; }; };
return CallNextHookEx (hKeyboardHook, nCode, wParam, lParam);
}
So then pushkey() becomes the problem.
It looks like you must use keybd_event() in a WH_KEYBOARD_LL proc.
Oh, wait, it's been superseded for NT/XP, use SendInput() instead. You
could use a single SendInput() to place all 6 key events (Back
Down/Up, 'E' Down/Up, 'i' Down/Up)
OTOH, if you use a "normal" keyboardhook, not the LL version, you
might be able to use
INPUT_RECORD input_record[3];
input_record[0].EventType = KEY_EVENT;
input_record[0].Event.KeyEvent = BackKeyEvent; /*user defined*/
input_record[1].EventType = KEY_EVENT;
input_record[1].Event.KeyEvent = eKeyEvent; /*user defined*/
input_record[2].EventType = KEY_EVENT;
input_record[2].Event.KeyEvent = iKeyEvent; /*user defined*/
WriteConsoleInput( GetStdHandle(STD_INPUT_HANDLE), &input_record, 3,
&w);
As an example, I use these KeyEvents
KEY_EVENT_RECORD EnterKeyEvent = {TRUE,1,0x0d,0x1c, 0x0d,0};
KEY_EVENT_RECORD InsertKeyEvent = {TRUE,1,0x2d,0x52, 0,0x100};
But, no guarantees here <G>.
Technical Details
Message-ID:
<rbm1svk8q490mo3us5p72nt9kke54u877k@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<2llvrv8g0ethuqm7b21760f21944k4qppp@4ax.com> <3fbff23d$1@newsgroups.borland.com> <rpm0sv46b9pkgk9tsmjgs21htn6gqnm0jj@4ax.com> <3fc06850$1@newsgroups.borland.com> <sui1sv89b9esc6nmg9m5205m3s4htt30k3@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,c26082be79ed8ef8 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-23 09:09:17 PST From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Simulating that a key has been pressed Date: Sun, 23 Nov 2003 08:58:38 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <rbm1svk8q490mo3us5p72nt9kke54u877k@4ax.com> References: <2llvrv8g0ethuqm7b21760f21944k4qppp@4ax.com> <3fbff23d$1@newsgroups.borland.com> <rpm0sv46b9pkgk9tsmjgs21htn6gqnm0jj@4ax.com> <3fc06850$1@newsgroups.borland.com> <sui1sv89b9esc6nmg9m5205m3s4htt30k3@4ax.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.31.164.132 X-Trace: newsgroups.borland.com 1069606723 67.31.164.132 (23 Nov 2003 08:58:43 -0700) Lines: 89 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail