Changeset 1704


Ignore:
Timestamp:
09/01/14 16:16:15 (10 years ago)
Author:
dmay
Message:

implement keypress modifiers: ctrl, shift, alt and alt graph - should be enough for now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java

    r1701 r1704  
    2222import java.util.ArrayList; 
    2323import java.util.Collection; 
     24import java.util.HashMap; 
    2425import java.util.Iterator; 
    2526import java.util.List; 
     
    9192    private JFCGUIElement currentFocus; 
    9293    private StructureNode structure; 
     94 
    9395    private StructureNode lastKeySequenceEvent; 
    9496    private StructureNode lastKeyTypedEvent; 
     97    private int currentKeyModifiers; 
     98 
     99    private HashMap<VirtualKey, Integer> modifiers; 
     100     
    95101    private StructureNode lastMouseClickEvent; 
    96102    private StructureNode lastFocusChangeEvent; 
     
    138144        sequences = (Collection<List<Event>>) dataObject; 
    139145 
     146        // map which maps VirtualKeys back to awt key modifier codes 
     147        modifiers = new HashMap<>(); 
     148        modifiers.put(VirtualKey.SHIFT, 1); 
     149        modifiers.put(VirtualKey.CONTROL, 2); 
     150        modifiers.put(VirtualKey.ALT, 8); 
     151        modifiers.put(VirtualKey.ALT_GRAPH, 32); 
     152        currentKeyModifiers = 0; 
     153         
    140154        writeJacaretoXML(sequences, filename); 
    141155    } 
     
    438452        KeyInteraction info = (KeyInteraction) event.getType(); 
    439453        JFCGUIElement target = (JFCGUIElement) event.getTarget(); 
    440  
     454        int keyCode = info.getKey().getVirtualKeyCode(); 
     455 
     456        applyKeyModifier(info.getKey(), jacId == 401); 
     457         
    441458        //@formatter:off 
    442459        writeLine(writer, 
     
    459476        writeLine(writer, 
    460477            "<KeyInfo " 
    461             + "keyCode=\"" + info.getKey().getVirtualKeyCode() + "\" " 
    462             + "keyChar=\"" + getKeyChar(info.getKey().getVirtualKeyCode()) + "\" " 
    463             + "modifiers=\"0\" />" 
     478            + "keyCode=\"" + keyCode + "\" " 
     479            + "keyChar=\"" + getKeyChar(keyCode) + "\" " 
     480            + "modifiers=\"" + currentKeyModifiers + "\" />" 
    464481        ); 
    465482         
     
    477494        } 
    478495    } 
     496     
     497    private void applyKeyModifier (VirtualKey key, boolean set) { 
     498        Integer modifier = modifiers.get(key); 
     499        if (modifier != null) { 
     500            if (set) { 
     501                currentKeyModifiers |= modifier; 
     502            } 
     503            else { 
     504                currentKeyModifiers &= ~modifier; 
     505            } 
     506        } 
     507    } 
    479508} 
Note: See TracChangeset for help on using the changeset viewer.