×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    6

    Keypress injection

    Hello.

    I need to do a global post of a keypress (unicode character) to the system, in case of an event in my application. Ie. my application gets some information from the network and send the unicode character to the system.

    I was wondering if this is possible for s40, i was unable to find anything about it. For s60 this seems possible using, according to this link http://www.developer.nokia.com/Commu...ate_a_keypress. However this is only for c++ so s60 only, not s40.

    Could someone comment on feasibility of it?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Keypress injection

    Hi rever111,

    If I understand correctly, you need to simulate a key press in Series 40 with Java. Why not call the keyPressed(int mykey) method and pass as argument the key whose keypress you want to simulate?
    Example:

    CanvasKeyPressed.java (MIDlet)
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class CanvasKeyPressed extends MIDlet implements CommandListener{
    	CanvasKey canvas;
    
      private Display display;
      Command myke=new Command("KeyPress2",Command.OK,0);
      
      public void startApp(){
      canvas = new CanvasKey();
      display = Display.getDisplay(this);
      display.setCurrent(canvas);
      canvas.addCommand(myke);
      canvas.setCommandListener(this);
      }
    
      public void pauseApp(){}
    
      public void destroyApp(boolean unconditional){}
    
    public void commandAction(Command c, Displayable d) {
    	if(c==myke)
    	{
    		canvas.keyPressed(2);
    	}
    	
    }
    }
    CanvasKey.java (class)
    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    
    
    class CanvasKey extends Canvas{
    
      private Font font;
      private String message = "[PRESS KEY]";
    
      public CanvasKey(){
      font = Font.getFont(Font.FACE_PROPORTIONAL, 
       Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
      }
    
      public void mypress(int akey)
      {
    	  keyPressed(akey);
      }
      public void paint(Graphics g){
      int width = getWidth();
      int height = getHeight();
    
      g.setColor(255, 0, 0);
      g.fillRect(0, 0, width - 1, height - 1);
      g.setColor(0, 0, 255);
      g.drawRect(0, 0, width - 1, height - 1);
      g.setFont(font);
    
      int x = width / 2;
      int y = height / 2;
    
      g.drawString(message, x, y, Graphics.BASELINE | Graphics.HCENTER);
      }
      
    
      protected void keyPressed(int keyCode){
    	  message="KeyCode is"+keyCode;
    	  repaint();
      }
    
    }

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    6

    Re: Keypress injection

    If i understand this correctly, this will only send the keypress to my application, is that correct?

    I need to send a keypress to another application, while my app is in the background. Send a keypress to another currently active application. Is that possible?

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Keypress injection

    Not possible on Series 40. Sorry.

    Hartti

  5. #5
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Keypress injection

    hartti is right,

    you cannot have multiple applications running on Series 40 devices, as you can on Symbian/S60 devices.

Similar Threads

  1. keypress closes on N95 8G
    By neibs in forum Symbian
    Replies: 2
    Last Post: 2011-10-23, 13:05
  2. keypress
    By intheworldofmyown in forum Mobile Java General
    Replies: 9
    Last Post: 2008-11-14, 04:08
  3. Keypress 1.02
    By manugarrote in forum Symbian
    Replies: 9
    Last Post: 2008-05-31, 15:46
  4. Help keypress
    By oper6600 in forum Symbian
    Replies: 1
    Last Post: 2006-11-21, 16:51
  5. about the keypress
    By yahyah_yy in forum Symbian
    Replies: 2
    Last Post: 2004-02-04, 16:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×