Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created May 17, 2020 12:32
Show Gist options
  • Save PJZ9n/3fdde98602b17a0003f3a6adf8cdf90b to your computer and use it in GitHub Desktop.
Save PJZ9n/3fdde98602b17a0003f3a6adf8cdf90b to your computer and use it in GitHub Desktop.
大文字アルファベットをキーコードに変換する
int stringToKeycode(String s) throws Exception {
switch (s) {
case "A":
return KeyEvent.VK_A;
case "B":
return KeyEvent.VK_B;
case "C":
return KeyEvent.VK_C;
case "D":
return KeyEvent.VK_D;
case "E":
return KeyEvent.VK_E;
case "F":
return KeyEvent.VK_F;
case "G":
return KeyEvent.VK_G;
case "H":
return KeyEvent.VK_H;
case "I":
return KeyEvent.VK_I;
case "J":
return KeyEvent.VK_J;
case "K":
return KeyEvent.VK_K;
case "L":
return KeyEvent.VK_N;
case "M":
return KeyEvent.VK_M;
case "N":
return KeyEvent.VK_N;
case "O":
return KeyEvent.VK_O;
case "P":
return KeyEvent.VK_P;
case "Q":
return KeyEvent.VK_Q;
case "R":
return KeyEvent.VK_R;
case "S":
return KeyEvent.VK_S;
case "T":
return KeyEvent.VK_T;
case "U":
return KeyEvent.VK_U;
case "V":
return KeyEvent.VK_V;
case "W":
return KeyEvent.VK_W;
case "X":
return KeyEvent.VK_X;
case "Y":
return KeyEvent.VK_Y;
case "Z":
return KeyEvent.VK_Z;
default:
throw new Exception();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment