Raising a keypress event without pressing a key
-
Greetings, As indicated in the title I am trying to work out how to raise a keypress event in code, something I cannot find an article or tutorial on anywhere!! Which, to me, would be counter-inuitive as it would seem to be incredibly simple. Any help would be greatly appreciated. Regards, Kutz _____________________ Don't take out the Magic Pen, Don't draw on the Infinity Board - Neil Young
-
Greetings, As indicated in the title I am trying to work out how to raise a keypress event in code, something I cannot find an article or tutorial on anywhere!! Which, to me, would be counter-inuitive as it would seem to be incredibly simple. Any help would be greatly appreciated. Regards, Kutz _____________________ Don't take out the Magic Pen, Don't draw on the Infinity Board - Neil Young
It's not counter-intuitive, really. If you have to that you need to execute from two of more different functions/methods, move that code to it's own function/method and call it from wherever you need with whatever parameters you need. It's much easier than trying to figure out how to create event parameters from scratch. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
It's not counter-intuitive, really. If you have to that you need to execute from two of more different functions/methods, move that code to it's own function/method and call it from wherever you need with whatever parameters you need. It's much easier than trying to figure out how to create event parameters from scratch. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Sorry mate, but your comment doesn't help me at all. I found it a little hard to understand actually. It's not about catching or handling an event, but simulating a user's keytouch. This is because there is no way to open a dateTimePicker's calendar dropdown from code (or at least none that I can find) so in order to make it appear, you could raise a keypress event which would then be automatically handled by the control and make the calendar appear. Is this any clearer? _____________________ Don't take out the Magic Pen, Don't draw on the Infinity Board - Neil Young
-
Sorry mate, but your comment doesn't help me at all. I found it a little hard to understand actually. It's not about catching or handling an event, but simulating a user's keytouch. This is because there is no way to open a dateTimePicker's calendar dropdown from code (or at least none that I can find) so in order to make it appear, you could raise a keypress event which would then be automatically handled by the control and make the calendar appear. Is this any clearer? _____________________ Don't take out the Magic Pen, Don't draw on the Infinity Board - Neil Young
Don't know if this is the best way to do what you want, but... Find the control window handle using the FindWindowEx API. Then use the SendMessage API to send it a message that simulates a left button mouse click. The tricky part is that a DateTimePicker behaves differently depending on where you click on it. But the control itself only exposes a single hwnd for the entire control. So you will have to figure out the correct message parameters to make it think you clicked on the drop button instead of the in the date text area. Run an application that has a DTPicker control, then use the Spy++ tool to log WM_USER and all mouse related messages, and study the results. Then it is matter of tinkering with the message parameters until you find what works. Good Luck ... Robert
-
Don't know if this is the best way to do what you want, but... Find the control window handle using the FindWindowEx API. Then use the SendMessage API to send it a message that simulates a left button mouse click. The tricky part is that a DateTimePicker behaves differently depending on where you click on it. But the control itself only exposes a single hwnd for the entire control. So you will have to figure out the correct message parameters to make it think you clicked on the drop button instead of the in the date text area. Run an application that has a DTPicker control, then use the Spy++ tool to log WM_USER and all mouse related messages, and study the results. Then it is matter of tinkering with the message parameters until you find what works. Good Luck ... Robert
Cheers for your help, Robert. I'm not 100% on how to use FindWindowEx just yet, but a little net research will probably clear that up. I get the general idea, but how to use some of the parameters will take a bit more thinking. Cheers mate, kutz _____________________ Don't take out the Magic Pen, Don't draw on the Infinity Board - Neil Young