468,765 Members | 1,726 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

how to use a string, char and KEYS properly?

I'm trying to create a form which a user can type out a key, and the
CTRL-ALT-SHIFT keys are recognized (via ModifiedKeys object) and then pass
the letter the user pressed to the windows API method for setting the
hotkey. My problem is that WIN API takes a Keys object/enumeration. I'm a
bit weak on that stuff, so I'm hoping someone can point me in the right
direction? I'm looking for a good link or just out right help, please?

If I have a string or char, how do I get a Keys from it? I'm sure this is a
newbie type of question, sorry.

Thanks for any help.
Nov 17 '05 #1
5 7783
Hi,

Can you retrieve the key from the KeyDown event? there on the parameters you
will find the Key structure filled

Otherwise you can raise the event System.Windows.Forms.KeyPressEventArgs and
pass the char letter, if you handle the event you will receive the Key
structure filled.

Hope this helps
Salva
"Flip" wrote:
I'm trying to create a form which a user can type out a key, and the
CTRL-ALT-SHIFT keys are recognized (via ModifiedKeys object) and then pass
the letter the user pressed to the windows API method for setting the
hotkey. My problem is that WIN API takes a Keys object/enumeration. I'm a
bit weak on that stuff, so I'm hoping someone can point me in the right
direction? I'm looking for a good link or just out right help, please?

If I have a string or char, how do I get a Keys from it? I'm sure this is a
newbie type of question, sorry.

Thanks for any help.

Nov 17 '05 #2
> Can you retrieve the key from the KeyDown event? there on the parameters
you
will find the Key structure filled Oh, ok, I was thinking I would have to do that, but I guess I was hoping to
avoid it and just use the KeyPress event, which I don't think has the Keys
object (but I could be wrong?).

Maybe I don't understand enumerations, but if I can't set one, how does the
win forms give me one with a value? That part confuses me. Can you
comment?

Doesn't the KeyDown event get fired many, many, many times though while the
key is down? Does that matter? Would the code just set the Keys value a
million times, and that's ok?
Otherwise you can raise the event System.Windows.Forms.KeyPressEventArgs
and
pass the char letter, if you handle the event you will receive the Key
structure filled. I like your previous suggestion, after all I'm a newbie to this and
delegates are on my next ToDo list. :>
Hope this helps

Yes, thank you very much! :> I'll get back to you with what I find out
tonight! :> Thanks Salva! :>
Nov 17 '05 #3
Hi, The keydown is fired everytime you press a key, only once, the events are:

KeyDown
KeyPress
KeyUp

An enumerator is simply a definition to make more readable the code, actualy
represent a number, try to convert a key to an int and you will see.

The event keydown is giving you the keycode enumerator and also the key code
(ascii code). Test this, trap the event a put a breakpoint in a simple
application, you can read the keycode once you press any key.

In order to convert in an easy way you can fire the event as well :

System.Windows.Forms.KeyPressEventArgs MyEvent = new KeyPressEventArgs(<put
your char here>), if the event is trapped you will get the Keycode for your
char.

hope this helps
Salva
"Salvador" wrote:
Hi,

Can you retrieve the key from the KeyDown event? there on the parameters you
will find the Key structure filled

Otherwise you can raise the event System.Windows.Forms.KeyPressEventArgs and
pass the char letter, if you handle the event you will receive the Key
structure filled.

Hope this helps
Salva
"Flip" wrote:
I'm trying to create a form which a user can type out a key, and the
CTRL-ALT-SHIFT keys are recognized (via ModifiedKeys object) and then pass
the letter the user pressed to the windows API method for setting the
hotkey. My problem is that WIN API takes a Keys object/enumeration. I'm a
bit weak on that stuff, so I'm hoping someone can point me in the right
direction? I'm looking for a good link or just out right help, please?

If I have a string or char, how do I get a Keys from it? I'm sure this is a
newbie type of question, sorry.

Thanks for any help.

Nov 17 '05 #4
> Hi, The keydown is fired everytime you press a key, only once, the events
are: I tried putting some Console.WriteLines() around those events (key down,
press, up), and yes, they fire once, but the problem was finding the letter
that was pressed. :< I would get a key up for each of the CTRL, ALT and the
letter, and the letter migth come first with the modifier keys afterwards.
An enumerator is simply a definition to make more readable the code,
actualy
represent a number, try to convert a key to an int and you will see. I was thinking about that last night after I tried some things,
unfortunately after I turned the computer off. DOH! My next problem is
setting the Keys object upon application start, without an event. But like
you say, if it's just an int, then I could save the char as an int to the
registry, then when the app starts, pull it out, and create a Keys object
with that char/int value. Will that work?
The event keydown is giving you the keycode enumerator and also the key
code

Can I use the KeyCode as the int?
Nov 17 '05 #5
> hope this helps
Salva

Howdy Salvador. It worked very nicely, thank you again.
Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mathieu Malaterre | last post: by
11 posts views Thread by Nobody | last post: by
16 posts views Thread by Christopher Benson-Manica | last post: by
4 posts views Thread by Simon Schaap | last post: by
17 posts views Thread by Chad Myers | last post: by
9 posts views Thread by Mark | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.