Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

OnChar event does not fire when I press a character

Tried on both V2.05 and V2.07:

If I press any character, or with Shift key on, or with Alt key on, the OnChar event does not get fired.
However, the OnChar event fires if I press any character with Ctrl key on.

Any clue for this, please?

Thanks, Ariel

Comments

  • Yes. There are couple reasons you don't get the event. First, the tree control consumes certain keystrokes because the keyboard can be used to navigate the control. All standard printable characters are consumed by the tree in order to allow users to quick-search for particular items. This even happens if the user is holding Shift, since Shift is often used in standard typing.

    However, the quick-search is skipped if the user is holding down either Control or Alt, in which case, the OnChar event is fired. This is why holding Control works.

    But why doesn't holding Alt work? Well, Alt is a bit trickier because that tells Windows that the user is attempting to use a menu shortcut. So, when you hold Alt, my tree control doesn't even know you've pressed other keys because the form's menu gets the keystrokes instead.

    So, if you are trying to implement Alt+K or Shift+K, for example, then you need to create a hidden menu item with that shortcut. In practice, this is the better way to implement shortcuts because it's more universal to the form anyway.
  • Thank you Kevin.

    However, by default, press a character will take me to the first word starting with this character only, and it won't listen to the second character.

    Hence, if I want to keep press characters for the 1st, 2nd, 3rd, then 4th, etc. character for finding a particular word, is there a way for implement that, please?

    Thanks again,
    Ariel
  • That's odd. I specifically implemented what you are asking when I first wrote the Tree control. In fact, I just tested it and was able to jump to a specific element in a non-sorted tree by typing multiple characters. If this is not working for you, try temporarily disabling the OnChar event of the tree and see if it kicks in. That would isolate whether or not some BASIC+ logic somewhere is interfering with the default behavior.
  • It works. Thank you. :-D

    I notice that there's time limitation for me to press one character after another. May I know the timing, please? In addition, is there a way to adjust the timing by myself in the code?

    Thanks again.
  • The time is 1 second. It is not currently something that can be customized, but since it was a simple request, I went ahead and implemented it for the next release.
  • Awesome :-)
    Thank you.
Sign In or Register to comment.