Zum Inhalt springen

Empfohlene Beiträge

Geschrieben (bearbeitet)

Hallo zusammen,

für ein Projekt von mir würd ich gerne wissen, ob und wie man eine deutsche Tastatureingabe auf eine englische Tastatureingabe um-mappen kann.

Das Problem:

Ich emuliere in JAVA die Schneider / Amstrad CPC Homecomputer.

Dort funzt die Tastatureingabe aber nur dann 100%, wenn ich lokal auf meinem PC die Tastatur auf Englisch umstelle.

Kann man dieses nicht auch in Java für eben diese Anwendung tun?

Hier meine Keyboard.java:

package jemu.system.cpc;


import java.awt.event.*;

import jemu.core.*;

import jemu.core.device.keyboard.*;


/**

 * Title:        JEMU

 * Description:  The Java Emulation Platform

 * Copyright:    Copyright (c) 2008

 * Company:

 * @author Markus

 * @version 5.1

 */


public abstract class Keyboard extends MatrixKeyboard {



  protected int[] bytes = new int[16];

  protected int row = 0;


  public Keyboard() {

    super("CPC Keyboard",8,10);

    for (int i = 0; i < bytes.length; i++)

      bytes[i] = 0xff;

    setKeyMappings();

    reset();

  }


  protected abstract void setKeyMappings();


  protected void keyChanged(int col, int row, int oldValue, int newValue) {

    if (oldValue == 0) {

      if (newValue != 0)

        bytes[row] &= (0x01 << col) ^ 0xff;

    }

    else if (newValue == 0)

      bytes[row] |= (0x01 << col);

  }


  public void setSelectedRow(int value) {

    row = value;

  }


  public int readSelectedRow() {

    return bytes[row];

  }


}

Dazu gehörend: KeyboardA.java
package jemu.system.cpc;


import java.awt.event.*;


/**

 * Title:        JEMU

 * Description:  The Java Emulation Platform

 * Copyright:    Copyright (c) 2002-2008

 * Company:

 * @author:      Markus

 * @version 5.1

 *

 *

 */


public class KeyboardA extends Keyboard {


  protected static final int[] KEY_MAP = {

    // Row 0

    KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_F9,

    KeyEvent.VK_F6, KeyEvent.VK_F3, KeyEvent.VK_END, KeyEvent.VK_DECIMAL,


    // Row 1

    KeyEvent.VK_LEFT, KeyEvent.VK_ALT, KeyEvent.VK_F7, KeyEvent.VK_F8,

    KeyEvent.VK_F5, KeyEvent.VK_F1, KeyEvent.VK_F2, KeyEvent.VK_F12,


    // Row 2

    -1/*KeyEvent.VK_BACK_QUOTE*/, KeyEvent.VK_ALT_GRAPH, KeyEvent.VK_ENTER,

    KeyEvent.VK_CLOSE_BRACKET, KeyEvent.VK_F4, KeyEvent.VK_SHIFT,

    KeyEvent.VK_BACK_SLASH, KeyEvent.VK_CONTROL,


    // Row 3

    KeyEvent.VK_EQUALS, KeyEvent.VK_MINUS, KeyEvent.VK_OPEN_BRACKET, KeyEvent.VK_P,

    KeyEvent.VK_QUOTE, KeyEvent.VK_SEMICOLON, KeyEvent.VK_SLASH, KeyEvent.VK_PERIOD,


    // Row 4

    KeyEvent.VK_0, KeyEvent.VK_9, KeyEvent.VK_O, KeyEvent.VK_I,

    KeyEvent.VK_L, KeyEvent.VK_K, KeyEvent.VK_M, KeyEvent.VK_COMMA,


    // Row 5

    KeyEvent.VK_8, KeyEvent.VK_7, KeyEvent.VK_U, KeyEvent.VK_Y,

    KeyEvent.VK_H, KeyEvent.VK_J, KeyEvent.VK_N, KeyEvent.VK_SPACE,


    // Row 6

    KeyEvent.VK_6, KeyEvent.VK_5, KeyEvent.VK_R, KeyEvent.VK_T,

    KeyEvent.VK_G, KeyEvent.VK_F, KeyEvent.VK_B, KeyEvent.VK_V,


    // Row 7

    KeyEvent.VK_4, KeyEvent.VK_3, KeyEvent.VK_E, KeyEvent.VK_W,

    KeyEvent.VK_S, KeyEvent.VK_D, KeyEvent.VK_C, KeyEvent.VK_X,


    // Row 8

    KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ESCAPE, KeyEvent.VK_Q,

    KeyEvent.VK_TAB, KeyEvent.VK_A, KeyEvent.VK_CAPS_LOCK, KeyEvent.VK_Z,


    // Row 9

    KeyEvent.VK_NUMPAD8, KeyEvent.VK_NUMPAD2, KeyEvent.VK_NUMPAD4, KeyEvent.VK_NUMPAD6,

    KeyEvent.VK_NUMPAD5, KeyEvent.VK_NUMPAD0, -1, KeyEvent.VK_BACK_SPACE

  };


  public void setKeyMappings() {

    addKeyMappings(KEY_MAP);


    // For MS JVM, these keys have different codes

    addKeyMapping(0xba,5,3);  // VK_SEMICOLON = 0xba

    addKeyMapping(0xbc,7,4);  // VK_COMMA = 0xbc

    addKeyMapping(0xbd,1,3);  // VK_MINUS = 0xbd

    addKeyMapping(0xbe,7,3);  // VK_PERIOD = 0xbe

    addKeyMapping(0xdb,2,3);  // VK_OPEN_BRACKET = 0xdb

    addKeyMapping(0xdd,3,2);  // VK_CLOSE_BRACKET = 0xdd

  }


}
Wer kann mir helfen???? LG Markus EDIT: Hier noch meine MatrixKeyboard.java:
package jemu.core.device.keyboard;


import java.awt.event.*;

import java.util.*;

import jemu.core.*;

import jemu.core.device.*;


/**

 * Title:        JEMU

 * Description:  The Java Emulation Platform

 * Copyright:    Copyright (c) 2007

 * Company:

 * @author

 * @version 1.0

 */


public class MatrixKeyboard extends Device {


  public static final int KEY_RIGHT = 0x10000;


  protected int[] pressMap = new int[0x1000];


  // Each key has a count of Java keys pressed for that key

  protected int[][] keyMap;


  // Each Integer Java key is mapped in this table to a mapping array

  protected Hashtable mappings = new Hashtable();


  public MatrixKeyboard(String type, int cols, int rows) {

    super("Matrix Keyboard");

    keyMap = new int[rows][cols];

  }


  public void reset() {

    for (int row = 0; row < keyMap.length; row++) {

      int[] keyRow = keyMap[row];

      for (int col = 0; col < keyRow.length; col++)

        setKeyMap(col,row,0);

    }

  }


  protected void setKeyMap(int col, int row, int value) {

    int oldValue = keyMap[row][col];

    if (oldValue != value) {

      keyMap[row][col] = value;

      //System.out.println("Key Changed: " + col + ", " + row);

      keyChanged(col,row,oldValue,value);

    }

  }


  public boolean isKeyPressed(int col, int row) {

    return row >= 0 && row < keyMap.length &&

      col >= 0 && col < keyMap[row].length && keyMap[row][col] != 0;

  }


  protected void keyChanged(int col, int row, int oldValue, int newValue) { }


  public void addKeyMapping(int key, int col, int row) {

    KeyMapping mapping = (KeyMapping)mappings.get(new Integer(key));

    if (mapping == null) {

      mapping = new KeyMapping();

      mappings.put(new Integer(key),mapping);

    }

    mapping.addMapping(col,row);

  }


  public void addKeyMappings(int[] map) {

    int cols = keyMap[0].length;

    for (int i = 0; i < map.length; i++)

      if (map[i] != -1)

        addKeyMapping(map[i],i % cols,i / cols);

  }


  public void addKeyMappings(int[][] map) {

    for (int row = 0; row < map.length; row++) {

      for (int col = 0; col < map[row].length; col++)

        if (map[row][col] != -1)

          addKeyMapping(map[row][col],col,row);

    }

  }


  public void removeKeyMapping(int key, int col, int row) {

    KeyMapping mapping = (KeyMapping)mappings.get(new Integer(key));

    if (mapping != null) {

      mapping.removeMapping(col,row);

      if (mapping.getCount() == 0)

        mappings.remove(mapping);

    }

  }


  public void keyPressed(int key) {

    keyPressed(key,KeyEvent.KEY_LOCATION_UNKNOWN);

  }


  public void keyPressed(int key, int location) {

    keyChange(key,location,1);

  }


  public void keyReleased(int key) {

    keyReleased(key,KeyEvent.KEY_LOCATION_UNKNOWN);

  }


  public void keyReleased(int key, int location) {

    keyChange(key,location,-1);

  }


  protected void keyChange(int key, int location, int step) {

//    System.out.println("key=" + Util.hex((short)key));

    int mask = 0x01 << (key & 0x1f);

    boolean right = location == KeyEvent.KEY_LOCATION_RIGHT;

    int offs = right ? 0x800 + key / 32 : key / 32;

    if (step != 1 || (pressMap[offs] & mask) == 0) {

      KeyMapping mapping = null;

      if (right)

        mapping = (KeyMapping)mappings.get(new Integer(key | KEY_RIGHT));

      if (mapping == null)

        mapping = (KeyMapping)mappings.get(new Integer(key));

      if (mapping != null)

        mapping.keyChange(step);

      if (step == 1)

        pressMap[offs] |= mask;

      else

        pressMap[offs] &= mask ^ 0xffffffff;

    }

  }


  protected class KeyMapping {

    protected int[] cols = new int[0];

    protected int[] rows = new int[0];


    protected void addMapping(int col, int row) {

      cols = Util.arrayInsert(cols,cols.length,1,col);

      rows = Util.arrayInsert(rows,rows.length,1,row);

    }


    protected void removeMapping(int col, int row) {

      for (int i = 0; i < cols.length; i++) {

        if (cols[i] == col && rows[i] == row) {

          cols = Util.arrayDelete(cols,i,1);

          rows = Util.arrayDelete(rows,i,1);

          break;

        }

      }

    }


    protected int getCount() {

      return cols.length;

    }


    protected void keyChange(int step) {

      for (int i = 0; i < cols.length; i++) {

        int col = cols[i];

        int row = rows[i];

        setKeyMap(col,row,Math.max(0,keyMap[row][col] + step));

      }

    }


  }


}

Bearbeitet von Devilmarkus

Dein Kommentar

Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung wiederherstellen

  Nur 75 Emojis sind erlaubt.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Editor leeren

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...