mIRC Homepage
Posted By: Yochai KEYDOWN for dialogs - 29/12/06 09:27 AM
Why isn't there a keydown event for dialogs ?
I think it would be pretty usefull to have a keydown event for dialogs as well as custom @windows.
I've encountered a few situations where I really neede to capture key events but couldn't, and then had to find ways to work around it.
Hmm, I hope it's not too difiicult, I'm sure it won't be too hard to make the On Keydown event apply to dialogs as well.
Posted By: Riamus2 Re: KEYDOWN for dialogs - 29/12/06 04:43 PM
That would be nice to have built in. I think DCX might have that ability, but I don't see it from a quick look at the website.
Posted By: ClickHeRe Re: KEYDOWN for dialogs - 30/12/06 02:06 AM
There isn't because keydown is a per control event in windows. The keyboard is trapped by the control/window that has the focus. In dialogs, the dialog window never has the focus it's always one of its child controls.

That's why there is no on keydown for dialogs. The only way to achieve this would be to intercept all keydown events on each control to relay them back in some fashion to simulate the event.

Posted By: Riamus2 Re: KEYDOWN for dialogs - 30/12/06 03:08 AM
What about a special hidden control that is always in focus and capture keypresses? Not sure how well that would work, but it's a thought.
Posted By: Sais Re: KEYDOWN for dialogs - 30/12/06 04:59 PM
Or have the child controls pass the keydown/up event up to their parent. That ought to be possible, but it is Windows, after all, so one can never be sure smile
Posted By: ClickHeRe Re: KEYDOWN for dialogs - 30/12/06 07:46 PM
only one control can have focus at one time, so if you are typing in an edit, the other control will not receive keyboard events!
Posted By: Mpdreamz Re: KEYDOWN for dialogs - 30/12/06 07:50 PM
A control that always takes focus is highly annoying :p
Event bubbling could work indeed smile
Posted By: Riamus2 Re: KEYDOWN for dialogs - 30/12/06 09:11 PM
Originally Posted By: ClickHeRe
only one control can have focus at one time, so if you are typing in an edit, the other control will not receive keyboard events!


If you're typing in an edit box, then it probably shouldn't track keyup/keydown either. I guess there may be a reason to do so in an edit box, but I'm thinking that most uses would be game related or similar and typing wouldn't be when you'd need to track the keypresses. I don't know... it was just a thought. I don't know much about how things work in the background, so I was just offering a suggestion. smile

It could be useful to have some kind of click once on a control to use (like you'd click a "window" -- whatever control you want to create that window with -- it will activate and then track keypresses). Then, if you click somewhere else, it will no longer track keypresses. For a game, this would let you run the game through this "window". It would be similar to how some activex and other scripting languages have you click on the window to use the control on a website. You could then have it also check the current mouse position only while it's over that "window" and when it's over it, you could have it draw in something such as crosshairs or a different mouse pointer. It's just too bad you can't hide the real mouse pointer. To point it out, I'm thinking of this window as if it were a picwin since that's where you could draw stuff. But it could really be various controls... even an icon. You just wouldn't be able to draw stuff in it that way.

Something like that could let you create a racing game inside a dialog and have arrow keys control your car as just one example. I know you can do this outside of a dialog. But inside a dialog could be nice if it was possible.
Posted By: CakerX Re: KEYDOWN for dialogs - 02/01/07 06:22 PM
I just started using dialogs last week.

I agree with the OP, how about adding keydown/keyup, or even keypress to the "on dialog" event.

on *:dialog:name:keydown:id:{commands}
Posted By: Riamus2 Re: KEYDOWN for dialogs - 02/01/07 11:02 PM
CakerX, if you want to check key presses in a specific ID, you can use DCX. I have DCX tracking the Enter key in an edit box to prevent having to use a hidden button to handle hitting Enter and having it move the edit line text into another control (in my case, a RichEdit control).

However, if you want keypresses for the DIALOG itself, that's where the problem comes in.
© mIRC Discussion Forums