question KbFiltr_ServiceCallback

I write some code in KbFiltr_ServiceCallback (kbfiltr.c),I want change some key’s scan code(A -> B),
When I press a key to test ,it seems right.
But When I pressed one key but not released for a while,even some minutes.It comes out only two letters. (when pressed, it comes out one ,and when released it comes out another ).
When I delete for(…), it also wrong. It comes up two different letters,some letters are
‘A’ and some letters are ‘B’.
Why?Can you tell me?

The main Code is Folling:
VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
{

PKEYBOARD_INPUT_DATA PKeyData = InputDataStart;
for(PKeyData ; PKeyData != InputDataEnd; PKeyData++)
{
g_ulCurrKeyScanCode =PKeyData->MakeCode;

if(g_ulCurrKeyScanCode == 0x1e )
{
PKeyData->MakeCode = 0x30;
}

}
}

Why even have g_ulCurrKeyScanCode? The MakeCode is going to be the same when you press or release the key (the difference is that the Flags will have KEY_BREAK set on release), so you can just replace value ‘A’ with value ‘B’ all the time if that is what you want to do.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@neusoft.com
Sent: Monday, June 02, 2008 11:21 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] question KbFiltr_ServiceCallback

I write some code in KbFiltr_ServiceCallback (kbfiltr.c),I want change some key’s scan code(A -> B),
When I press a key to test ,it seems right.
But When I pressed one key but not released for a while,even some minutes.It comes out only two letters. (when pressed, it comes out one ,and when released it comes out another ).
When I delete for(…), it also wrong. It comes up two different letters,some letters are
‘A’ and some letters are ‘B’.
Why?Can you tell me?

The main Code is Folling:
VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
{

PKEYBOARD_INPUT_DATA PKeyData = InputDataStart;
for(PKeyData ; PKeyData != InputDataEnd; PKeyData++)
{
g_ulCurrKeyScanCode =PKeyData->MakeCode;

if(g_ulCurrKeyScanCode == 0x1e )
{
PKeyData->MakeCode = 0x30;
}

}
}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

g_ulCurrKeyScanCode is a variable.
ULONG g_ulCurrKeyScanCode = 0;

you said I know,I use only the folling code(I think it will execute the folling code, no matter the Flags is KEY_BREAK or KEY_MAKE ),When I press a key and release it immediately, It is right.
But When I press the key but not release.It also wrong.It can come up lots of letters,but some are ‘A’ and some are ‘B’. The result is not I want. I want the letters is the same.

if(PKeyData->MakeCode== 0x1e )
{
PKeyData->MakeCode = 0x30;
}

It’s very hard to understand what your question is.

What is the exact sequence of keys you press and release, and what is
the exact sequence of keystrokes (make and break) that you see come out,
and what did you expect to see?

Oh, and what are you using to observe the data coming out? Debug output?
Notepad? Stepping through in WinDbg?

This code should work (assuming you actually call KBDCLASS’s service
callback at the end of this function, unlike what you showed).

xxxxx@neusoft.com wrote:

I write some code in KbFiltr_ServiceCallback (kbfiltr.c),I want change some key’s scan code(A -> B),
When I press a key to test ,it seems right.
But When I pressed one key but not released for a while,even some minutes.It comes out only two letters. (when pressed, it comes out one ,and when released it comes out another ).
When I delete for(…), it also wrong. It comes up two different letters,some letters are
‘A’ and some letters are ‘B’.
Why?Can you tell me?

The main Code is Folling:
VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
{

PKEYBOARD_INPUT_DATA PKeyData = InputDataStart;
for(PKeyData ; PKeyData != InputDataEnd; PKeyData++)
{
g_ulCurrKeyScanCode =PKeyData->MakeCode;

if(g_ulCurrKeyScanCode == 0x1e )
{
PKeyData->MakeCode = 0x30;
}

}
}


Ray
(If you want to reply to me off list, please remove “spamblock.” from my
email address)

Thanks Doron Holan and Thanks Ray Trent.
Drion Holan what you said can satisfy my requirement,use the following code is right.
if(PKeyData->MakeCode== 0x1e )
{
PKeyData->MakeCode = 0x30;
}

At first ,I can not get what I want ,because the other code which I not write here is wrong .
I use a thread.but not right.

Why do you have a thread? Why not just change the values in your service callback and then call the upper service callback in the same context? Can post all of the code related to the service callback and thread?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@neusoft.com
Sent: Tuesday, June 03, 2008 7:18 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] question KbFiltr_ServiceCallback

Thanks Doron Holan and Thanks Ray Trent.
Drion Holan what you said can satisfy my requirement,use the following code is right.
if(PKeyData->MakeCode== 0x1e )
{
PKeyData->MakeCode = 0x30;
}

At first ,I can not get what I want ,because the other code which I not write here is wrong .
I use a thread.but not right.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

hi Doron Holan,
Thanks !
(I want my application can get the scan code .)
I have alread delete the thread which I want to store scan code. Instead of it ,I use only one global variable to store the pressed key scan code. The application can get scan code.when one key is pressed ,and release it at now. But I find a problem and I do not know how to do.When the application is getting the scan code,the next key is pressed,I think the driver should wait the application get scan code. But I feel it not a good idea.Can you give me some advice?
All above.

I have to ask…how much experience do you have writing user mode software,let alone kernel mode software? From the sound of it, not much. I would suggest that get some computer science books, esp ones on multi threaded synchronization (Richter’s Windows via C/C++ is quite good, http://www.amazon.com/gp/product/0735624240/ref=pd_cp_b_2?pf_rd_p=317711001&pf_rd_s=center-41&pf_rd_t=201&pf_rd_i=0735621632&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=1SV1XPRY4CYRHXTWC1XP) as well as a book on data structures.

What you need to do is use 2 design patterns. The first is an io queue of pended irps. The second is a ring buffer of scan codes. The basic idea is this

  1. when you get a ioctl to retrieve the scan code, you check the ring buffer. If an entry is present, pop it off and complete the irp immediately. If no entry is present, put the irp on the queue
  2. when you get a scan code in the service callback, check to see if there are any irps in the queue. If so, pop one off and complete it with the data, otherwise add an entry to the ring buffer

Note that if you use KMDF to write your driver, you get an io queue impl for free and you are on much more stable ground. Also note that kbdclass does exactly this, so you even have code to copy from/help you. Look at KbdClassServiceCallback and the IRP_MJ_READ handler to see how both the queue and ring buffer work

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@neusoft.com
Sent: Wednesday, June 04, 2008 12:11 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] question KbFiltr_ServiceCallback

hi Doron Holan,
Thanks !
(I want my application can get the scan code .)
I have alread delete the thread which I want to store scan code. Instead of it ,I use only one global variable to store the pressed key scan code. The application can get scan code.when one key is pressed ,and release it at now. But I find a problem and I do not know how to do.When the application is getting the scan code,the next key is pressed,I think the driver should wait the application get scan code. But I feel it not a good idea.Can you give me some advice?
All above.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Doron Holan,
I am ashame to say that I have learn driver only three weeks.Although everyday I use much time to study it ,I find I know little about it.
Thanks Dorno , Thanks your advice! I know what I can do!

Yes, don’t use a thread. Besides all the synchronization problems, any
thread would be running at PASSIVE_LEVEL, and the MOUCLASS service
callback has to be called at DISPATCH_LEVEL, which you could do… of
course… but why bother?

Doron Holan wrote:

Why do you have a thread? Why not just change the values in your service callback and then call the upper service callback in the same context? Can post all of the code related to the service callback and thread?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@neusoft.com
Sent: Tuesday, June 03, 2008 7:18 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] question KbFiltr_ServiceCallback

Thanks Doron Holan and Thanks Ray Trent.
Drion Holan what you said can satisfy my requirement,use the following code is right.
if(PKeyData->MakeCode== 0x1e )
{
PKeyData->MakeCode = 0x30;
}

At first ,I can not get what I want ,because the other code which I not write here is wrong .
I use a thread.but not right.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Ray
(If you want to reply to me off list, please remove “spamblock.” from my
email address)