本文整理匯總了Java中java.awt.event.KeyEvent.getKeyChar方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.getKeyChar方法的具體用法?Java KeyEvent.getKeyChar怎麽用?Java KeyEvent.getKeyChar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getKeyChar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: keyReleased
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override public void keyReleased(KeyEvent e) {
// System.out.println("key release");
Character n = new Character(e.getKeyChar());
try {
for (int i = 0; i < keysDown.size(); i++) {
if (keysDown.get(i).equals(n)) {
keysReleased.add(keysDown.get(i));
keysDown.remove(i);
keyrCheckInitiated = false;
i--;
}
}
}// end try
catch (Exception ex) {
System.out
.println("Unexpected thread sync conflict in key detection.\n---Problem has been handled, but may have lost key input in the process.");
ex.printStackTrace();
}
}
示例2: keyReleased
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyChar()) {
case 'w':
scrollThread.setKeyUp(false);
break;
case 'd':
scrollThread.setKeyRight(false);
break;
case 's':
scrollThread.setKeyDown(false);
break;
case 'a':
scrollThread.setKeyLeft(false);
break;
}
}
示例3: processKeyEvent
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void processKeyEvent (KeyEvent evt) {
if (evt.getID() == KeyEvent.KEY_TYPED) {
char c = evt.getKeyChar();
JTextComponent component = (JTextComponent)evt.getSource();
if (confirmChars == null) {
confirmChars = getConfirmChars(component);
}
if (confirmChars.indexOf(c) != -1) {
if (c != '.') {
Completion.get().hideDocumentation();
Completion.get().hideCompletion();
}
NbEditorDocument doc = (NbEditorDocument) component.getDocument ();
try {
defaultAction(component);
doc.insertString(processKeyEventOffset, Character.toString(c), null);
} catch (BadLocationException e) {
}
if (c == '.')
Completion.get().showCompletion();
evt.consume();
} // if
} // if
}
示例4: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyTyped(KeyEvent e) {
int keyCode = e.getKeyCode();
char keyChar = e.getKeyChar();
if (state == 3) {
if (keyCode != 0) {
throw new RuntimeException("Key code should be undefined.");
}
if (keyChar != 0xE1) {
throw new RuntimeException("A char does not have ACCUTE accent");
}
} else {
throw new RuntimeException("Wron number of keyTyped events.");
}
}
示例5: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyTyped(Canvas canvas, KeyEvent e) {
char ch = e.getKeyChar();
Selection selected = canvas.getSelection();
if ((ch == '\u0008' || ch == '\u007F') && !selected.isEmpty()) {
ArrayList<CanvasObject> toRemove = new ArrayList<CanvasObject>();
for (CanvasObject shape : selected.getSelected()) {
if (shape.canRemove()) {
toRemove.add(shape);
}
}
if (!toRemove.isEmpty()) {
e.consume();
CanvasModel model = canvas.getModel();
canvas.doAction(new ModelRemoveAction(model, toRemove));
selected.clearSelected();
repaintArea(canvas);
}
} else if (ch == '\u001b' && !selected.isEmpty()) {
selected.clearSelected();
repaintArea(canvas);
}
}
示例6: keyPressed
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
char keyChar = e.getKeyChar();
switch (state) {
case 0:
if (keyCode != KeyEvent.VK_ALT) {
throw new RuntimeException("Alt is not pressed.");
}
state++;
break;
case 1:
if (keyCode != KeyEvent.VK_DEAD_ACUTE) {
throw new RuntimeException("Dead ACUTE is not pressed.");
}
if (keyChar != 0xB4) {
throw new RuntimeException("Pressed char is not dead acute.");
}
state++;
break;
}
}
示例7: processKeyEvent
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void processKeyEvent(KeyEvent evt) {
if (evt.getID() == KeyEvent.KEY_TYPED) {
switch (evt.getKeyChar()) {
case ';':
case ',':
case '(':
case '.':
case '\n':
Completion.get().hideAll();
// case '.':
// JTextComponent component = (JTextComponent)evt.getSource();
// int caretOffset = component.getSelectionEnd();
// substituteText(component, substitutionOffset, caretOffset - substitutionOffset, Character.toString(evt.getKeyChar()));
// evt.consume();
// break;
}
}
}
示例8: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyTyped(KeyEvent ke) {
// forward space and b (toggle direction of playback) to AEPlayer
int k = ke.getKeyChar();
// log.info("keyChar=" + k + " keyEvent=" + ke.toString());
if (shiftPressed || ctlPressed) { // only forward to AEViewer if we are blocking ordinary input to AEViewer by labeling
switch (k) {
case KeyEvent.VK_SPACE:
chip.getAeViewer().setPaused(!chip.getAeViewer().isPaused());
break;
case KeyEvent.VK_B:
case 2:
chip.getAeViewer().getAePlayer().toggleDirection();
break;
case 'F':
case 6:
chip.getAeViewer().getAePlayer().speedUp();
break;
case 'S':
case 19:
chip.getAeViewer().getAePlayer().slowDown();
break;
}
}
}
示例9: changeOffset
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
* Increment the offset of the screen. Takes in a key which indicates the direction to move the offset
*
* @param e the key event containing the direction key
*/
protected void changeOffset(KeyEvent e)
{
if(e.getKeyChar() == 'w')
offset.addset(new Vector(0,1));
else if(e.getKeyChar() == 's')
offset.addset(new Vector(0,-1));
else if(e.getKeyChar() == 'a')
offset.addset(new Vector(-1,0));
else if(e.getKeyChar() == 'd')
offset.addset(new Vector(1,0));
}
示例10: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyTyped(KeyEvent k) {
if (k.getKeyChar() == '\n' && k.isControlDown()) {
k.consume();
execute();
}
}
示例11: getOldEventKey
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
static int getOldEventKey(KeyEvent e) {
int keyCode = e.getKeyCode();
for (int i = 0; i < actionKeyCodes.length; i++) {
if (actionKeyCodes[i][0] == keyCode) {
return actionKeyCodes[i][1];
}
}
return (int)e.getKeyChar();
}
示例12: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
e.consume();
if(compter < results.size()-Parser.numberVariableOfCurrentQuery()) {
if(e.getKeyChar() == '+'){
int i = compter+Parser.numberVariableOfCurrentQuery();
while (!results.get(i).equals("newLine")){
FromGui.insert(PrincipalWindow.interpreter,
" "+results.get(i).toString(), Color.BLACK);
i++;
}
compter= compter + Parser.numberVariableOfCurrentQuery() +1;
FromGui.insert(PrincipalWindow.interpreter, " \n", Color.BLACK);
}
else if (e.getKeyChar() == '/'){
for (int i=compter+Parser.numberVariableOfCurrentQuery(); i<results.size(); i++)
if (results.get(i).equals("newLine"))
FromGui.insert(PrincipalWindow.interpreter, " \n", Color.BLACK);
else
FromGui.insert(PrincipalWindow.interpreter,
" "+results.get(i).toString(), Color.BLACK);
compter = results.size();
}
else if (e.getKeyChar() == '.'){
PrincipalWindow.interpreter.removeKeyListener(this);
PrincipalWindow.interpreter.addKeyListener(new KeyMonitor());
FromGui.insert(PrincipalWindow.interpreter, "/> ", Color.BLACK);
}
PrincipalWindow.interpreter.setCaretPosition(PrincipalWindow.interpreter.getDocument().getLength());
}
else {
PrincipalWindow.interpreter.removeKeyListener(this);
PrincipalWindow.interpreter.addKeyListener(new KeyMonitor());
FromGui.insert(PrincipalWindow.interpreter, "/> ", Color.BLACK);
PrincipalWindow.interpreter.setCaretPosition(PrincipalWindow.interpreter.getDocument().getLength());
}
}
示例13: getKeyListener
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
private KeyListener getKeyListener() {
KeyAdapter listener = new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if(Character.isLetter(c) && !e.isAltDown()) {
e.consume();
}
}
};
return listener;
}
示例14: keyPressed
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
char keyChar = e.getKeyChar();
switch (state) {
case 0:
if (keyCode != KeyEvent.VK_ALT) {
throw new RuntimeException("Alt is not pressed.");
}
state++;
break;
case 1:
if (keyCode != KeyEvent.VK_DEAD_ACUTE) {
throw new RuntimeException("Dead ACUTE is not pressed.");
}
if (keyChar != 0xB4) {
throw new RuntimeException("Pressed char is not dead acute.");
}
state++;
break;
case 2:
if (keyCode != KeyEvent.VK_A) {
throw new RuntimeException("A is not pressed.");
}
if (keyChar != 0xE1) {
throw new RuntimeException("A char does not have ACCUTE accent");
}
state++;
break;
default:
throw new RuntimeException("Excessive keyPressed event.");
}
}
示例15: keyTyped
import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
* Method declaration
*
*
* @param k
*/
public void keyTyped(KeyEvent k) {
// Strg+Enter or Shift+Enter executes the actual SQL statement in command panel
if (k.getKeyChar() == '\n'
&& (k.isControlDown() || k.isShiftDown())) {
k.consume();
execute();
layoutCard.show(pCard, "result");
}
}