|
-
November 30th, 2008, 07:18 AM
#1
Keyboard filtering
Hello,
In my MFC application I want a keyboard filter so that on some situations only expected keys are accepted.
Example:
An edit control accepting only binary digits (0 or 1), all other keys beeing rejected.
I think OnKeyDown has to be customized but I am not sure
Thank you in helping me.
Whitebird001
-
November 30th, 2008, 07:38 AM
#2
Re: Keyboard filtering
have a look at this
Keyboard Hook
-
November 30th, 2008, 12:23 PM
#3
Re: Keyboard filtering
Try subclassing the edit control and handle OnSysKeyDown().
Regards,
John
http://www.simpletools.co.in
-
November 30th, 2008, 12:59 PM
#4
Re: Keyboard filtering
 Originally Posted by Cpp_Noob
Keyboard[/url]
Unnecessary, overkill.
 Originally Posted by unnamed
Try subclassing the edit control
Subclassing is good.
Details:
Derive class using CEdit as a base class. Subclass control using Wizard. Add member variable using derived class for a variable type "control" (not a string). This will insert DDX calls necessary to subclass control.
 Originally Posted by unnamed
handle OnSysKeyDown().

Insert handler for WM_CHAR message in CEdit derived class. In the handler, filter characters you need by returning from the handler without calling a base class. You can also consider beep to let user know that wrong character was entered.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
December 1st, 2008, 12:47 AM
#5
Re: Keyboard filtering
 Originally Posted by JohnCz

Insert handler for WM_CHAR message in CEdit derived class. In the handler, filter characters you need by returning from the handler without calling a base class. You can also consider beep to let user know that wrong character was entered.
Sorry, I had OnKeyDown in my mind.
-
December 1st, 2008, 05:39 AM
#6
Re: Keyboard filtering
 Originally Posted by whitebird001
Example:
An edit control accepting only binary digits (0 or 1), all other keys beeing rejected.
I think OnKeyDown has to be customized but I am not sure
The task (as it exactly is) is solved by ES_NUMBER edit control style.
Best regards,
Igor
-
December 1st, 2008, 05:57 AM
#7
Re: Keyboard filtering
 Originally Posted by Igor Vartanov
How?
First it allows also digits from 2 to 9 to be entered.
Second (from this link):
ES_NUMBER
Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong.
Victor Nijegorodov
-
December 1st, 2008, 06:11 AM
#8
Re: Keyboard filtering
Sorry, you're right, I have missed the point of 0/1. But regarding possible paste, the requirement to filter edit box text changes is different from filtering key presses.
Best regards,
Igor
-
December 1st, 2008, 06:16 AM
#9
Re: Keyboard filtering
 Originally Posted by Igor Vartanov
... But regarding possible paste, the requirement to filter edit box text changes is different from filtering key presses. 
Yes, of course!.
And I am sorry too, this part (about pasting problem) was not for you but for OP!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|