Index: /applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java
===================================================================
--- /applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java	(revision 31103)
+++ /applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java	(revision 31104)
@@ -6,5 +6,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.AWTEvent;
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -15,5 +14,4 @@
 import java.awt.RenderingHints;
 import java.awt.Toolkit;
-import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
@@ -22,4 +20,6 @@
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.openstreetmap.josm.Main;
@@ -37,9 +37,12 @@
 import org.openstreetmap.josm.gui.layer.MapViewPaintable;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
+import org.openstreetmap.josm.gui.util.ModifierListener;
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.Shortcut;
 
 @SuppressWarnings("serial")
-public class DrawBuildingAction extends MapMode implements MapViewPaintable, AWTEventListener, SelectionChangedListener {
+public class DrawBuildingAction extends MapMode implements MapViewPaintable, SelectionChangedListener,
+        KeyPressReleaseListener, ModifierListener {
     private enum Mode {
         None, Drawing, DrawingWidth, DrawingAngFix
@@ -54,10 +57,7 @@
     private Mode nextMode = Mode.None;
 
-    private final Color selectedColor;
+    private Color selectedColor = Color.red;
     private Point drawStartPos;
     private Point mousePos;
-    private boolean isCtrlDown;
-    private boolean isShiftDown;
-    private boolean isAltDown;
 
     final Building building = new Building();
@@ -73,6 +73,4 @@
         cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
         currCursor = cursorCrosshair;
-
-        selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
     }
 
@@ -113,5 +111,5 @@
     private void showAddrDialog(Way w) {
         AddressDialog dlg = new AddressDialog();
-        if (!isAltDown) {
+        if (!alt) {
             dlg.showDialog();
             if (dlg.getValue() != 1)
@@ -134,15 +132,13 @@
             return;
         }
+        selectedColor = Main.pref.getColor(marktr("selected"), selectedColor);
         currCursor = cursorCrosshair;
         Main.map.mapView.addMouseListener(this);
         Main.map.mapView.addMouseMotionListener(this);
         Main.map.mapView.addTemporaryLayer(this);
+        Main.map.keyDetector.addKeyListener(this);
+        Main.map.keyDetector.addModifierListener(this);
         DataSet.addSelectionListener(this);
         updateSnap(getCurrentDataSet().getSelected());
-        try {
-            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
-        } catch (SecurityException ex) {
-            Main.error(ex);
-        }
     }
 
@@ -153,10 +149,7 @@
         Main.map.mapView.removeMouseMotionListener(this);
         Main.map.mapView.removeTemporaryLayer(this);
+        Main.map.keyDetector.removeKeyListener(this);
+        Main.map.keyDetector.removeModifierListener(this);
         DataSet.removeSelectionListener(this);
-        try {
-            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
-        } catch (SecurityException ex) {
-            Main.error(ex);
-        }
         if (mode != Mode.None)
             Main.map.mapView.repaint();
@@ -176,14 +169,9 @@
 
     @Override
-    public void eventDispatched(AWTEvent arg0) {
-        if (!(arg0 instanceof KeyEvent))
-            return;
-        KeyEvent ev = (KeyEvent) arg0;
-        int modifiers = ev.getModifiersEx();
-        boolean isCtrlDown = (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0;
-        boolean isShiftDown = (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0;
-        if (this.isCtrlDown != isCtrlDown || this.isShiftDown != isShiftDown) {
-            this.isCtrlDown = isCtrlDown;
-            this.isShiftDown = isShiftDown;
+    public void modifiersChanged(int modifiers) {
+        boolean oldCtrl = ctrl;
+        boolean oldShift = shift;
+        updateKeyModifiers(modifiers);
+        if (ctrl != oldCtrl || shift != oldShift) {
             processMouseEvent(null);
             updCursor();
@@ -191,18 +179,23 @@
                 Main.map.mapView.repaint();
         }
-        isAltDown = (modifiers & KeyEvent.ALT_DOWN_MASK) != 0;
-
-        if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {
-            if (mode != Mode.None) {
-                ev.consume();
-            }
+    }
+
+    @Override
+    public void doKeyPressed(KeyEvent e) {
+        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+            if (mode != Mode.None)
+                e.consume();
 
             cancelDrawing();
         }
+    }
+
+    @Override
+    public void doKeyReleased(KeyEvent e) {
     }
 
     private EastNorth getEastNorth() {
         Node n;
-        if (isCtrlDown) {
+        if (ctrl) {
             n = null;
         } else {
@@ -217,5 +210,5 @@
 
     private boolean isRectDrawing() {
-        return building.isRectDrawing() && (!isShiftDown || ToolSettings.isBBMode());
+        return building.isRectDrawing() && (!shift || ToolSettings.isBBMode());
     }
 
@@ -224,7 +217,7 @@
         if (isRectDrawing()) {
             building.setPlaceRect(p);
-            return isShiftDown ? Mode.DrawingAngFix : Mode.None;
-        } else {
-            building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), isShiftDown);
+            return shift ? Mode.DrawingAngFix : Mode.None;
+        } else {
+            building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), shift);
             Main.map.statusLine.setDist(building.getLength());
             this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None;
@@ -247,7 +240,5 @@
         if (e != null) {
             mousePos = e.getPoint();
-            isCtrlDown = e.isControlDown();
-            isShiftDown = e.isShiftDown();
-            isAltDown = e.isAltDown();
+            updateKeyModifiers(e);
         }
         if (mode == Mode.None) {
@@ -310,10 +301,11 @@
             Way w = building.create();
             if (w != null) {
-                if (!isAltDown || ToolSettings.isUsingAddr())
-                    w.setKeys(ToolSettings.getTags());
+                if (!alt || ToolSettings.isUsingAddr())
+                    for (Entry<String, String> kv : ToolSettings.getTags().entrySet())
+                        w.put(kv.getKey(), kv.getValue());
                 if (ToolSettings.isUsingAddr())
                     showAddrDialog(w);
                 if (ToolSettings.isAutoSelect()
-                        && (Main.main.getCurrentDataSet().getSelected().isEmpty() || isShiftDown)) {
+                        && (Main.main.getCurrentDataSet().getSelected().isEmpty() || shift)) {
                     Main.main.getCurrentDataSet().setSelected(w);
                 }
@@ -369,10 +361,10 @@
             return;
         Node n = null;
-        if (!isCtrlDown)
+        if (!ctrl)
             n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
         if (n != null) {
             setCursor(cursorJoinNode);
         } else {
-            if (customCursor != null && (!isShiftDown || isRectDrawing()))
+            if (customCursor != null && (!ctrl || isRectDrawing()))
                 setCursor(customCursor);
             else
