View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Mon Oct 01, 2007 3:13 pm Post subject: SHIFT key + label_doubleClick |
|
|
Greetings.
Is there a way to tell if the shift key is being pushed, while a label (say label_2) is double clicked? I am adding 1 to a value while double clicking on label_2, but I want to add 5 when the shift key is down.
Is this possible or is there any other way of doing this?
thanks,
jic |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Oct 02, 2007 12:56 am Post subject: Re: SHIFT key + label_doubleClick |
|
|
You can just test if(Control.modifierKeys & Keys.SHIFT) in your click handler. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Tue Oct 02, 2007 7:17 am Post subject: |
|
|
thanks. That worked. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Tue Oct 02, 2007 12:43 pm Post subject: |
|
|
The first double click with the SHIFT key pressed does not work. For example, I press the SHIFT key and then I double click on the label and the wrong event gets executed (the one with the SHIFT key not pressed). Any idea how to make it work correctly?
thanks,
jic |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Wed Oct 03, 2007 9:06 am Post subject: |
|
|
It seems to be working good here. I might need more info to help. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Wed Oct 03, 2007 4:08 pm Post subject: |
|
|
if it is working for you, I must be doing something wrong... .-)
I'll try to figure it out.
thanks. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Oct 11, 2007 1:54 pm Post subject: |
|
|
just to complete the thread, I was not doing something wrong, but I was missing another spot that I was not checking for the click handler.
DFL is great! Thanks!
jic |
|
Back to top |
|
|
baxissimo
Joined: 23 Oct 2006 Posts: 241 Location: Tokyo, Japan
|
Posted: Thu Nov 15, 2007 11:46 pm Post subject: Re: SHIFT key + label_doubleClick |
|
|
Chris Miller wrote: | You can just test if(Control.modifierKeys & Keys.SHIFT) in your click handler. |
I think a better way is to pass the current key state along with the MouseEventArgs. The wParam for WM_MOUSEMOVE tells you right there what the modifier key state is, so you might as well pass it along to the user.
(http://msdn2.microsoft.com/en-us/library/ms645616.aspx)
Relying on GetAsyncKeyState is not so good because (I think) there's no equivalent to it on some platforms. So it could be a problem going forward with the GTK port and other ports in the future.
Anyway, I was surprised to find that the key state was not passed as part of the mouse event args. I think it should be added. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Fri Nov 16, 2007 10:43 am Post subject: |
|
|
I agree. And also, there should be a way of passing variables to those event functions. I like passing variables to functions, but there is not way, that I know of, of passing my variables to these functions.
just a thought...
jic |
|
Back to top |
|
|
baxissimo
Joined: 23 Oct 2006 Posts: 241 Location: Tokyo, Japan
|
Posted: Fri Nov 16, 2007 2:55 pm Post subject: |
|
|
jicman wrote: | there should be a way of passing variables to those event functions. I like passing variables to functions, but there is not way, that I know of, of passing my variables to these functions.
just a thought...
jic |
You mean something like this?
Code: |
setCallback(&myfunction, &myData);
...
myfunction(EventArgs ea, void *yourData) {
// yourData points to myData
}
|
Well I've seen that done in various C-ish callback schemes (such as in FLTK), but I don't think that's so necessary in D.
For one, D has delegates, so the function you're passing as a callback already has a sort of "myData" pointer in it that points to the enclosing context. If a method delegate it points to the enclosing class, if function delegate it points to the enclosing scope. So you can stick your myData in that enclosing scope.
And for D2.0 with real closures now, it's even less of a necessity, because you really will be able to wrap up whatever data you want in a function. Something like:
Code: |
exitButton.click ~= (Object s,EventArgs a){
onExitWithData(s,a, myData);
};
|
With closures myData can be anything in the enclosing scope or a new value if you prefer or whatever. Proper closures means it will make it through in tact to the onExitWithData call, whenever that happens.
That's assuming DFL is going to move to D2.0 eventually. |
|
Back to top |
|
|
|