I have sub-classed the TextBox. In its OnKeyDown event I can intercept key
strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want
to change it to another unicode key from a different code page (e.g.,
"\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs
are all only getters. They are read only and thus do not permit changing the
assigned KeyCode. My question is this: How do I change the KeyCode of the
KeyEvenetArgs to be a different key? I tired to call base.OnKeyDown( ) passing
a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes
an instance of Keys, and THAT constructor takes no argument. Even if I create
an instance of Keys, then I'm faced with the read only nature of KeyCode,
KeyData, etc. It seems to be a vicious circle. Any help would be appreciated. 6 3912
The Keys required by KeyEventArgs is an enumerated type, you don't use
the constructor. For example, to simulate pressing Enter:
new KeyEventArgs(Ke ys.Enter)
I don't think you'll be able to do your code page translation with the
KeyEventArgs class.
Do you have to use OnKeyDown? Would OnKeyPress meet your needs?
protected override void OnKeyPress(KeyP ressEventArgs e)
{
// perform your logic to get the key from another codepage
Char newChar = translateChar(e .KeyChar);
base.OnKeyPress (new KeyPressEventAr gs(newChar));
}
Joshua Flanagan http://flimflan.com/blog
Z wrote: I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode of the KeyEvenetArgs to be a different key? I tired to call base.OnKeyDown( ) passing a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes an instance of Keys, and THAT constructor takes no argument. Even if I create an instance of Keys, then I'm faced with the read only nature of KeyCode, KeyData, etc. It seems to be a vicious circle. Any help would be appreciated.
Thanks, Joshua, for your suggestion. This does work as you say. One problem
remains, and that is that the cursor (or caret) does not advance past the
newly inserted character. Guess I'll now have to work on developing a custom
Caret class that I will control via code. Thanks again for your help.
"Joshua Flanagan" wrote: The Keys required by KeyEventArgs is an enumerated type, you don't use the constructor. For example, to simulate pressing Enter: new KeyEventArgs(Ke ys.Enter)
I don't think you'll be able to do your code page translation with the KeyEventArgs class.
Do you have to use OnKeyDown? Would OnKeyPress meet your needs?
protected override void OnKeyPress(KeyP ressEventArgs e) { // perform your logic to get the key from another codepage Char newChar = translateChar(e .KeyChar); base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Joshua Flanagan http://flimflan.com/blog
Z wrote: I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode of the KeyEvenetArgs to be a different key? I tired to call base.OnKeyDown( ) passing a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes an instance of Keys, and THAT constructor takes no argument. Even if I create an instance of Keys, then I'm faced with the read only nature of KeyCode, KeyData, etc. It seems to be a vicious circle. Any help would be appreciated.
Actually, on closer inspection, it does not work. I still had remnants of
code left in OnKeyDown and that was getting in the way. In OnKeyDown I can
call a method that accepts the character I want to display instead of the
character that was typed, and that method just concatenates that new char to
the existing chars already in the TextBox. Although this does work, the
cursor (as I mentioned) does not advance. But calling
base.OnKeyPress (newchar) does not render the new character. The typed
character is the one that shows up.
"Z" wrote: Thanks, Joshua, for your suggestion. This does work as you say. One problem remains, and that is that the cursor (or caret) does not advance past the newly inserted character. Guess I'll now have to work on developing a custom Caret class that I will control via code. Thanks again for your help.
"Joshua Flanagan" wrote:
The Keys required by KeyEventArgs is an enumerated type, you don't use the constructor. For example, to simulate pressing Enter: new KeyEventArgs(Ke ys.Enter)
I don't think you'll be able to do your code page translation with the KeyEventArgs class.
Do you have to use OnKeyDown? Would OnKeyPress meet your needs?
protected override void OnKeyPress(KeyP ressEventArgs e) { // perform your logic to get the key from another codepage Char newChar = translateChar(e .KeyChar); base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Joshua Flanagan http://flimflan.com/blog
Z wrote: I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode of the KeyEvenetArgs to be a different key? I tired to call base.OnKeyDown( ) passing a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes an instance of Keys, and THAT constructor takes no argument. Even if I create an instance of Keys, then I'm faced with the read only nature of KeyCode, KeyData, etc. It seems to be a vicious circle. Any help would be appreciated.
This worked for me
protected override void OnKeyPress(KeyP ressEventArgs e) {
//translate your character - I use ToUpper just for an example
Char newChar = Char.ToUpper(e. KeyChar);
this.Text += newChar;
// set the caret to the end
this.SelectionS tart = this.Text.Lengt h;
// tell the rest of the event chain there is no further work to do
e.Handled = true;
// I'm not sure if this line is necessary. it works without it
base.OnKeyPress (new KeyPressEventAr gs(newChar));
}
Z wrote: Actually, on closer inspection, it does not work. I still had remnants of code left in OnKeyDown and that was getting in the way. In OnKeyDown I can call a method that accepts the character I want to display instead of the character that was typed, and that method just concatenates that new char to the existing chars already in the TextBox. Although this does work, the cursor (as I mentioned) does not advance. But calling base.OnKeyPress (newchar) does not render the new character. The typed character is the one that shows up.
"Z" wrote:
Thanks, Joshua, for your suggestion. This does work as you say. One problem remains, and that is that the cursor (or caret) does not advance past the newly inserted character. Guess I'll now have to work on developing a custom Caret class that I will control via code. Thanks again for your help.
"Joshua Flanagan" wrote:
The Keys required by KeyEventArgs is an enumerated type, you don't use the constructor. For example, to simulate pressing Enter: new KeyEventArgs(Ke ys.Enter)
I don't think you'll be able to do your code page translation with the KeyEventAr gs class.
Do you have to use OnKeyDown? Would OnKeyPress meet your needs?
protected override void OnKeyPress(KeyP ressEventArgs e) { // perform your logic to get the key from another codepage Char newChar = translateChar(e .KeyChar); base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Joshua Flanagan http://flimflan.com/blog
Z wrote:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801") . But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode of the KeyEvenetAr gs to be a different key? I tired to call base.OnKeyDown( ) passing a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes an instance of Keys, and THAT constructor takes no argument. Even if I create an instance of Keys, then I'm faced with the read only nature of KeyCode, KeyData, etc. It seems to be a vicious circle. Any help would be appreciated.
Thanks, Joshua. I will give it a try and report back. I have to go teach a
class right now. P.S. Enjoyed your web site.
"Joshua Flanagan" wrote: This worked for me
protected override void OnKeyPress(KeyP ressEventArgs e) { //translate your character - I use ToUpper just for an example Char newChar = Char.ToUpper(e. KeyChar); this.Text += newChar; // set the caret to the end this.SelectionS tart = this.Text.Lengt h; // tell the rest of the event chain there is no further work to do e.Handled = true; // I'm not sure if this line is necessary. it works without it base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Yep. Works good. Thanks again.
"Joshua Flanagan" wrote: This worked for me
protected override void OnKeyPress(KeyP ressEventArgs e) { //translate your character - I use ToUpper just for an example Char newChar = Char.ToUpper(e. KeyChar); this.Text += newChar; // set the caret to the end this.SelectionS tart = this.Text.Lengt h; // tell the rest of the event chain there is no further work to do e.Handled = true; // I'm not sure if this line is necessary. it works without it base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Z wrote: Actually, on closer inspection, it does not work. I still had remnants of code left in OnKeyDown and that was getting in the way. In OnKeyDown I can call a method that accepts the character I want to display instead of the character that was typed, and that method just concatenates that new char to the existing chars already in the TextBox. Although this does work, the cursor (as I mentioned) does not advance. But calling base.OnKeyPress (newchar) does not render the new character. The typed character is the one that shows up.
"Z" wrote:
Thanks, Joshua, for your suggestion. This does work as you say. One problem remains, and that is that the cursor (or caret) does not advance past the newly inserted character. Guess I'll now have to work on developing a custom Caret class that I will control via code. Thanks again for your help.
"Joshua Flanagan" wrote:
The Keys required by KeyEventArgs is an enumerated type, you don't use the constructor. For example, to simulate pressing Enter: new KeyEventArgs(Ke ys.Enter)
I don't think you'll be able to do your code page translation with the KeyEventAr gs class.
Do you have to use OnKeyDown? Would OnKeyPress meet your needs?
protected override void OnKeyPress(KeyP ressEventArgs e) { // perform your logic to get the key from another codepage Char newChar = translateChar(e .KeyChar); base.OnKeyPress (new KeyPressEventAr gs(newChar)); }
Joshua Flanagan http://flimflan.com/blog
Z wrote:
>I have sub-classed the TextBox. In its OnKeyDown event I can intercept key >strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want >to change it to another unicode key from a different code page (e.g., >"\u2801") . But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs >are all only getters. They are read only and thus do not permit changing the >assigned KeyCode. My question is this: How do I change the KeyCode of the >KeyEvenetAr gs to be a different key? I tired to call base.OnKeyDown( ) passing >a new instance of KeyEventArgs, but the constructor for KeyEventArgs() takes >an instance of Keys, and THAT constructor takes no argument. Even if I create >an instance of Keys, then I'm faced with the read only nature of KeyCode, >KeyData, etc. It seems to be a vicious circle. Any help would be appreciated. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: oeyvind toft |
last post by:
How do I capture the ctrl keypress?
Is it possible for js to intercept the ctrl-n combination and prevent
the creation of a new IE window??
(Have 3 huge books on js and none of them mention this subject)
Oeyvind
|
by: Matthew |
last post by:
I have this code snippet that is ignoring a Tab key and executing
something(); on all other key-presses. How would I efficiently modify
this to include a second key, such as backspace (KeyCode 8)?
onkeydown="if ((event.keyCode||event.which) != 9) { something(); }"
|
by: songkau |
last post by:
Why doesn't this work? :-
<BODY onkeydown="display(event)">
<input type="text" name="text1">
<script language="Javascript">
function display(event) {
document.text1.value = event.keyCode+' : '+String.fromCharCode(event.keyCode);
}
</script>
</BODY>
|
by: Julia Briggs |
last post by:
Are there any gotchas using if (event.keyCode==8)? I understand that
to represent backspace, but it doesn't work. I am running Windows XP,
using a typical keyboard - but no luck in detecting backspaces. Anyone
have experiences with this?
|
by: Z |
last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key
strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want
to change it to another unicode key from a different code page (e.g.,
"\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs
are all only getters. They are read only and thus do not permit changing the
assigned KeyCode. My question is this: How do I change the KeyCode...
| |
by: Pugi! |
last post by:
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using
Javascript & DOM'.
function aKeyWasPressed(e) {
if (window.event) {
var key = window.event.keyCode;
} else {
var key = e.keyCode;
}
alert('You pressed the key: ' + String.fromCharCode(key));
|
by: WilliamRLinden |
last post by:
Hi world! we are pretty new to JavaScript and have been
struggling for now 2 days on this problem ... We would
appreciate mercy if anyone can give us some.
Basically we are trying to simulate the tab key when the
down arrow key is pressed. (we know there are other way
to control focus flow but we use a lot of dynamic jsp fields,
that will make the flow control a nightmare, we just want
basic tabbing from the arrow key)
|
by: Paul Gorodyansky |
last post by:
Hi,
I have function that works via onkeypressed -
for example, what to catch when a user presses a punctuation symbol
such as '.'
So I check keyCode for that - works just fine in
Opera 8, Mozilla/Firefox, IE
|
by: ShayHk |
last post by:
hi
I want to know if there is a way to change the keycode on press
the main goal
is to switch any languagh to english
for example
when I press on "×" (hebrew) the output will return as "t"..
thanks
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |