I'm using **Libgdx**, input events don't work when using **Multi-OS Engine** - ios

It works fine in Android and Desktop. But when running on iOS, it doesn't respond any input event.
I'm using gdxVersion 1.9.5, multi-os engine 1.2.3
I wrote a test class extends input adapter and override touchDown and touchUp method. But it doesn't respond any of the input events which work fine in Android.
public class TestScreen extends ScreenAdapter implements InputProcessor {
private CardGame game;
private OrthographicCamera guiCam;
public TestScreen(CardGame game){
this.game = game;
guiCam = new OrthographicCamera(Consts.WORLD_WIDTH, Consts.WORLD_HEIGHT);
Gdx.input.setInputProcessor(this);
}
public void draw () {
GL20 gl = Gdx.gl;
gl.glClearColor(1, 0, 0, 1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
guiCam.update();
}
public void render (float delta) {
draw();
}
#Override
public boolean keyDown(int keycode) {
System.out.println("key down");
return true;
}
#Override
public boolean keyUp(int keycode) {
System.out.println("key up");
return true;
}
#Override
public boolean keyTyped(char character) {
System.out.println("key typed");
return true;
}
#Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
System.out.println("touch down");
return true;
}
#Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
System.out.println("touch up");
return true;
}
#Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
System.out.println("touch dragged");
return true;
}
#Override
public boolean mouseMoved(int screenX, int screenY) {
System.out.println("mouse moved");
return true;
}
#Override
public boolean scrolled(int amount) {
System.out.println("scrolled");
return true;
}
}

Related

How to get new edit Text on Enter Key pressed event in Dialogbox using Android programing? Can you provide sample code for that?

I had tried through below code but not getting key event.
editText1.setOnKeyListener(new OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
if((event.getAction()==KeyEvent.ACTION_DOWN)&&(keyCode==KeyEvent.KEYCODE_ENTER))
{
editText1.clearFocus();
editText2.requestFocus();
return true;
}
return false;
}
});
use event.getKeyCode() instead of just keyCode
editText1.setOnKeyListener(new OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
if((event.getAction()==KeyEvent.ACTION_DOWN)&&(event.getKeyCode()==KeyEvent.KEYCODE_ENTER))
{
editText1.clearFocus();
editText2.requestFocus();
return true;
}
return false;
}
});
I would use Textwatcher instead:
try this
editText1.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (s.length()>0 && s.subSequence(s.length()-1, s.length()).toString().equalsIgnoreCase("\n"))
{
editText1.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
editText1.clearFocus();
editText2.requestFocus();
}
}
});

I cannot access the KeyPressed function for when i press the ESCAPE key

The first problem is that the addKeyListener does is redlined wherever I place it. I've looked at various different examples online but it seems that Im missing something.
here is my code:
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
public class BBMIDLET extends javax.microedition.midlet.MIDlet implements KeyListener
public void startApp() {
Display.init(this);
addKeyListener(new TestKeyPadListener());
}
public class TestKeyPadListener implements KeyListener {
public boolean keyChar(char key, int status, int time) {
System.out.println("key: " + key);
return false;
}
public boolean keyDown(int keycode, int time) {
System.out.println("keycode: " + keycode);
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
System.out.println("Hi");
return false;
}
return true;
}
public boolean keyUp(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean keyRepeat(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean keyStatus(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}
Thanks in advance
addKeyListener(KeyListener l) is not a method of javax.microedition.midlet.MIDlet or net.rim.device.api.system.KeyListener and you did not declare it anywhere else in your BBMIDLET class so it is undefined.

Touch Event in Blackberry?

I am developing one blackerry application both touch and non-touch device. I am using custom button in my app. This is my code
package CustomControls;
import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*;
public class ImageButton extends Field {
private int width;
private int height;
private Bitmap focusImage;
private Bitmap unfocusImage;
private boolean focusFlag=false;
private Bitmap image;
private String label;
private Font font;
public ImageButton()
{
}
public ImageButton(Bitmap focusImage,Bitmap unfocusImage,int width,int height,long style)
{
super(style);
label="";
this.focusImage=focusImage;
this.unfocusImage=unfocusImage;
image=unfocusImage;
this.width=width;
this.height=height;
}
public ImageButton(String label,Font font,Bitmap focusImage,Bitmap unfocusImage,int width,int height,long style)
{
super(style);
this.label=label;
this.font=font;
this.focusImage=focusImage;
this.unfocusImage=unfocusImage;
image=unfocusImage;
this.width=width;
this.height=height;
}
public int getPreferredHeight()
{
return height;
}
public int getPreferredWidth()
{
return width;
}
protected void onFocus(int direction)
{
image=focusImage;
invalidate();
}
protected void onUnfocus()
{
image=unfocusImage;
invalidate();
}
public void setChangeImage(Bitmap fImage,Bitmap uImage)
{
focusImage=fImage;
unfocusImage=uImage;
image=fImage;
invalidate();
}
protected void drawFocus(Graphics graphics, boolean on)
{
}
protected void layout(int width, int height)
{
setExtent(Math.min( width, getPreferredWidth()),Math.min(height, getPreferredHeight()));
}
protected void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, getWidth(),getHeight(), image, 0, 0);
if(label.length()>0)
{
graphics.setFont(font);
graphics.drawText(label,(width-(label.length()*2))/2,(height-font.getHeight()));
}
}
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(1);
return true;
}
protected void fieldChangeNotify(int context)
{
try
{
this.getChangeListener().fieldChanged(this,context);
}
catch (Exception exception)
{
System.out.println("==> Exception in Touch "+exception.toString());
}
}
protected boolean navigationMovement(int dx, int dy, int status,int time)
{
return true;
}
protected boolean touchEvent(TouchEvent message)
{
if (TouchEvent.CLICK == message.getEvent())
{
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
protected boolean trackwheelRoll(int dir, int status, int time)
{
return true;
}
public void setBounds(int xPosition,int yPosition)
{
FieldPosition.setXPosition(this,xPosition);
FieldPosition.setYPosition(this,yPosition);
} }
I don't have problem in testing by using Simulator. But i am not able to navigate to button in Real device. I am using 9780 Blackberry bold device. I dont know where the problem occur
Try to do the following:
1). Remove this stuff:
protected boolean navigationMovement(int dx, int dy, int status,int time)
{
return true;
}
protected boolean trackwheelRoll(int dir, int status, int time)
{
return true;
}
2). Make sure your field IS focusable. As the docs say:
If you want your field to receive the
focus, then you must override
isFocusable to return true.
P.S. Actually you don't need to override the touchEvent(TouchEvent message). Check my another post on this.

BlackBerry Bitmap listener

I have a code similar to the one below, painting over the mapfields this mIcon several times.
How can I add a click listener to this bitmap ? I am using bb 5.0
public Bitmap mIcon;
mIcon = Bitmap.getBitmapResource("pcture1.png");
protected void paint(Graphics g) {
super.paint(g);
mDest = new XYRect(....);
g.drawBitmap(mDest, mIcon, 0, 0);
}
Override BitmapField and modify the isFocusable(), navigationClick(), keyChar(), and trackwheelClick() methods.
public class ImageButtonField extends BitmapField
{
public ImageButtonField(Bitmap image)
{
super(image);
}
public boolean isFocusable()
{
return true;
}
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(0);
return true;
}
protected boolean trackwheelClick(int status, int time)
{
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time)
{
if(Characters.ENTER == character || Characters.SPACE == character)
{
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}

Working example of JNA mouse hook

Can any one provide me with a working example of JNA mouse hook, which would be able to track mouse movements/click outside my Java Swing application ?
Thanks in Advance
Yep, here is the code...
public class CWMouseHook {
public final User32 USER32INST;
public final Kernel32 KERNEL32INST;
public CWMouseHook()
{
if(!Platform.isWindows())
{
throw new UnsupportedOperationException("Not supported on this platform.");
}
USER32INST = User32.INSTANCE;
KERNEL32INST = Kernel32.INSTANCE;
mouseHook=hookTheMouse();
Native.setProtected(true);
}
public static LowLevelMouseProc mouseHook;
public HHOOK hhk;
public Thread thrd;
public boolean threadFinish = true;
public boolean isHooked = false;
public static final int WM_MOUSEMOVE = 512;
public static final int WM_LBUTTONDOWN = 513;
public static final int WM_LBUTTONUP = 514;
public static final int WM_RBUTTONDOWN = 516;
public static final int WM_RBUTTONUP = 517;
public static final int WM_MBUTTONDOWN = 519;
public static final int WM_MBUTTONUP = 520;
public void unsetMouseHook()
{
threadFinish = true;
if (thrd.isAlive())
{
thrd.interrupt();
thrd = null;
}
isHooked = false;
}
public boolean isIsHooked()
{
return isHooked;
}
public void setMouseHook()
{
thrd = new Thread(new Runnable() {
#Override
public void run()
{
try
{
if(!isHooked)
{
hhk = USER32INST.SetWindowsHookEx(14, mouseHook,KERNEL32INST.GetModuleHandle(null),0);
isHooked = true;
MSG msg = new MSG();
while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0)
{
USER32INST.TranslateMessage(msg);
USER32INST.DispatchMessage(msg);
System.out.print(isHooked);
if (!isHooked)
break;
}
}
else
System.out.println("The Hook is already installed.");
}
catch (Exception e)
{ System.err.println(e.getMessage());
System.err.println("Caught exception in MouseHook!");
}
}
},"Named thread");
threadFinish = false;
thrd.start();
}
private interface LowLevelMouseProc extends HOOKPROC
{
LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT lParam);
}
public LowLevelMouseProc hookTheMouse() {
return new LowLevelMouseProc()
{
#Override
public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) {
if (nCode >= 0)
{
switch(wParam.intValue())
{
case CWMouseHook.WM_LBUTTONDOWN:
// do stuff
break;
case CWMouseHook.WM_RBUTTONDOWN:
//do stuff
break;
case CWMouseHook.WM_MBUTTONDOWN:
//do other stuff
break;
case CWMouseHook.WM_LBUTTONUP:
//do even more stuff
break;
case CWMouseHook.WM_MOUSEMOVE:
break;
default:
break;
}
/****************************DO NOT CHANGE, this code unhooks mouse *********************************/
if (threadFinish == true)
{
USER32INST.PostQuitMessage(0);
}
/***************************END OF UNCHANGABLE *******************************************************/
}
return USER32INST.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}
};
}
public class Point extends Structure
{
public class ByReference extends Point implements Structure.ByReference {};
public NativeLong x;
public NativeLong y;
}
public static class MOUSEHOOKSTRUCT extends Structure
{
public static class ByReference extends MOUSEHOOKSTRUCT implements Structure.ByReference {};
public POINT pt;
public HWND hwnd;
public int wHitTestCode;
public ULONG_PTR dwExtraInfo;
}
That's all about there is to it. Cheers.
It's a basically a ripoff of the code of a guy in Sun forums...but also tested by me, and it works so cheers again.
Edit: I edited the code so it includes the LowLevelMouseProc but you can use your extension of HOOK which you can define elsewhere. It doesn't matter that much. Be wary that for some reason you have TO have the variable mouseHook as static otherwise hook just unhooks after a while.
movements:
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.mouse.NativeMouseWheelEvent;
import org.jnativehook.mouse.NativeMouseWheelListener;
public class GlobalMouseWheelListenerExample implements NativeMouseWheelListener {
public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
System.out.println("Mosue Wheel Moved: " + e.getWheelRotation());
}
public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
} catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
ex.printStackTrace();
System.exit(1);
}
// Construct the example object and initialze native hook.
GlobalScreen.getInstance().addNativeMouseWheelListener(new GlobalMouseWheelListenerExample());
}
}
click:
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseInputListener;
public class GlobalMouseListenerExample implements NativeMouseInputListener {
public void nativeMouseClicked(NativeMouseEvent e) {
System.out.println("Mosue Clicked: " + e.getClickCount());
}
public void nativeMousePressed(NativeMouseEvent e) {
System.out.println("Mosue Pressed: " + e.getButton());
}
public void nativeMouseReleased(NativeMouseEvent e) {
System.out.println("Mosue Released: " + e.getButton());
}
public void nativeMouseMoved(NativeMouseEvent e) {
System.out.println("Mosue Moved: " + e.getX() + ", " + e.getY());
}
public void nativeMouseDragged(NativeMouseEvent e) {
System.out.println("Mosue Dragged: " + e.getX() + ", " + e.getY());
}
public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
//Construct the example object.
GlobalMouseListenerExample example = new GlobalMouseListenerExample();
//Add the appropriate listeners for the example object.
GlobalScreen.getInstance().addNativeMouseListener(example);
GlobalScreen.getInstance().addNativeMouseMotionListener(example);
}
}

Resources