On 7/1/10 9:26 AM, Peter Körner wrote: > Hi > > I'm using a DrawFeature to add marker to a map. I want the user to be > able to place one marker at a time, so I used the featureAdded callback > and disabled the DrawFeature-Control there. > > Next I want the user to be able to override this behavior by holding the > ctrl-key (add a marker with each click), so I need to get the ctrl-key > status in the featureAdded callback. > > Is there any cross-browser / well-defined way in OpenLayers to do this? >
The DrawFeature control's featureAdded callback will not help out here. While it may not get at what you're after, you can set the keyMask property of your sketch handler to modify the behavior of the control. So, to create a DrawFeature control that only responds if the ctrl key is down (during a mousedown), the following should work: var control = new OpenLayers.Control.DrawFeature( layer, OpenLayers.Handler.Point, { handlerOptions: {keyMask: OpenLayers.Handler.MOD_SHIFT} } ); http://dev.openlayers.org/apidocs/files/OpenLayers/Handler-js.html#OpenLayers.Handler.keyMask In general (with OpenLayers alone), you can't get the current status of a key (ctrl up or whatever) unless you are registered as a listener for a key or mouse event. The featureAdded callback is called during one of these listener sequences (mouseup), but it doesn't get the arguments you need. It could make sense for the "featureadded" event to be triggered with the actual mouse event. In this case, you could do what you like with key modifiers. Tim > Sorry If the answer is on the ML-Archives or on the wiki but I missed > it. A link will do in this case. > > Peter > _______________________________________________ > Dev mailing list > Dev@openlayers.org > http://openlayers.org/mailman/listinfo/dev -- Tim Schaub OpenGeo - http://opengeo.org Expert service straight from the developers. _______________________________________________ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev