Skip to content

Instantly share code, notes, and snippets.

@TheRealGuru
Created April 26, 2017 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRealGuru/32a76d37486f49bcdb3af6f930649e89 to your computer and use it in GitHub Desktop.
Save TheRealGuru/32a76d37486f49bcdb3af6f930649e89 to your computer and use it in GitHub Desktop.
KeyboardSetting.java
package com.prime.bots.test;
import com.runemate.game.api.hybrid.local.Varbit;
import com.runemate.game.api.hybrid.local.Varbits;
import java.awt.event.KeyEvent;
import java.util.Arrays;
/**
* OSRS Specific Class
* Used for getting the players keybind for a certain interface
*/
public enum KeyboardSetting {
COMBAT(4675),
SKILL(4676),
QUEST(4677),
INVENTORY(4678),
EQUIPMENT(4679),
PRAYER(4680),
ESC_CLOSE(4681),
SPELLBOOK(4682),
CLAN(4683),
FRIENDS(4684),
IGNORE(4685),
OPTIONS(4686),
EMOTES(4687),
MUSIC(4688),
LOGOUT(4689);
//Varbit index is the index of the control varbit
private int varbitIndex;
KeyboardSetting( int varbitIndex ) {
this.varbitIndex = varbitIndex;
}
/**
* Gets the value of the varbit using the varbit index
* @return Returns varbit value
*/
private int getVarbitValue() {
Varbit varbit = Varbits.load( varbitIndex );
if( varbit != null ) {
return varbit.getValue();
}
return -1;
}
/**
* Gets the SettingKey for this component
* @return Returns the SettingKey
*/
public SettingKey getKey() {
int varbitValue = getVarbitValue();
if( varbitValue == -1 ) {
return null;
}
return SettingKey.getKey( varbitValue );
}
public enum SettingKey {
NONE(0, -1),
F1(1, KeyEvent.VK_F1),
F2(2, KeyEvent.VK_F2),
F3(3, KeyEvent.VK_F3),
F4(4, KeyEvent.VK_F4),
F5(5, KeyEvent.VK_F5),
F6(6, KeyEvent.VK_F6),
F7(7, KeyEvent.VK_F7),
F8(8, KeyEvent.VK_F8),
F9(9, KeyEvent.VK_F9),
F10(10, KeyEvent.VK_F10),
F11(11, KeyEvent.VK_F11),
F12(12, KeyEvent.VK_F12),
ESC(13, KeyEvent.VK_ESCAPE);
private int varbitValue;
private int keyCode;
/**
*
* @param varbitValue is the value of the key when it is represented as a varbit
* @param keyCode is the KeyEvent key code for the key
*/
SettingKey( int varbitValue, int keyCode ) {
this.varbitValue = varbitValue;
this.keyCode = keyCode;
}
/**
*
* @return Returns the varbit value representation of the key
*/
public int getVarbitValue() {
return varbitValue;
}
/**
* Gets the Key number to press to activate this SettingKey
* @return Returns the Key Code
*/
public int getKeyCode() {
return keyCode;
}
/**
*
* @param varbitValue Finds the key that belongs to the varbit provided.
* @return The SettingKey found.
*/
private static SettingKey getKey( int varbitValue ) {
return Arrays.stream( values() ).filter( sk -> sk.getVarbitValue() == varbitValue ).findFirst().orElse( null );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment