Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.KeyEvent;
- import java.util.Timer;
- import java.util.TimerTask;
- import org.havi.ui.HSinglelineEntry;
- import org.havi.ui.event.HRcEvent;
- public class KeyboardController {
- private final static int timeInSeconds = 2;
- private KeyEvent event;
- private HSinglelineEntry in;
- private static int lastKey = -1;
- private static int pressCounter = 0;
- private static Timer timer = new Timer();
- private static int sync = 1;
- private int selected;
- public KeyboardController(KeyEvent e, HSinglelineEntry input) {
- event=e;
- in=input;
- }
- public void selectKeyboard() {
- if(lastKey == event.getKeyCode() && sync > 0) {
- sync++;
- }
- else {
- pressCounter = 0;
- sync = 1;
- lastKey = event.getKeyCode();
- }
- selected=pressCounter++ % 3;
- timer.schedule(new ResetButton(in), timeInSeconds * 1000);
- switch(event.getKeyCode()){
- case HRcEvent.VK_ENTER:
- in.setEditMode(false);
- break;
- case HRcEvent.VK_RIGHT:
- in.setCaretCharPosition(in.getCaretCharPosition()+1);
- break;
- case HRcEvent.VK_LEFT:
- if(in.getCaretCharPosition()>0)
- in.setCaretCharPosition(in.getCaretCharPosition()-1);
- break;
- case HRcEvent.VK_2:
- if(selected==0)
- in.insertChar('a');
- else if(selected==1)
- in.insertChar('b');
- else if(selected==2)
- in.insertChar('c');
- break;
- ...
- }
- }
- static class ResetButton extends TimerTask {
- HSinglelineEntry in;
- public ResetButton(HSinglelineEntry input) {
- in=input;
- }
- @Override
- public void run() {
- // This timer is finished
- if(sync > 0)
- sync--;
- in.setCaretCharPosition(in.getCaretCharPosition()+1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement