locked
Determining What Key Was Pressed Using Dispatcher.AcceleratorKeyActivated RRS feed

  • Question

  • I need to handle certain keyboard events, so I added a handler to the Dispatcher.AcceleratorKeyActivated event. The handler looks like the following:
    Private Sub Dispatcher_AcceleratorKeyActivated(sender As CoreDispatcher, e As AcceleratorKeyEventArgs)

    The part of the handler that I am having trouble getting to work is when I need to determine whether the key pressed is a letter. I would have thought that using a Boolean expression such as:
    If e.VirtualKey >= VirtualKey.A AndAlso e.VirtualKey <= VirtualKey.Z Then

    Would let me handle only letters and do nothing with other keys, but that doesn't seem to be working. Do I need to manually convert e.VirtualKey to it's enum type before comparing? Is their some special way to do the comparisons? All the VirtualKeys have constant numeric values, and all I am trying to do is use some simple operators. I could obviously look at every value individually, but that would be extremely inefficient. Can somebody help me here? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Tuesday, February 4, 2014 3:29 AM

Answers

  • You can use a Boolean expression such as that.

    In what way is this not working for you? Can you provide more information about what you are trying to do, what the non-working code looks like, and the difference between the expected and the actual behavior?

    --Rob

    Tuesday, February 4, 2014 5:27 AM
    Moderator

All replies

  • You can use a Boolean expression such as that.

    In what way is this not working for you? Can you provide more information about what you are trying to do, what the non-working code looks like, and the difference between the expected and the actual behavior?

    --Rob

    Tuesday, February 4, 2014 5:27 AM
    Moderator
  • I think I must have missed something else somewhere before, because I got it working now. I probably just had a mistake in the statements inside the If that I didn't realize weren't doing anything. But it's all good now, and it's good to know that I am using the appropriate Boolean expression(s), so I will say thank you for that confirmation. Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Tuesday, February 4, 2014 4:57 PM