Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
bertonlu
Posts: 3
Registered: ‎11-18-2012
My Device: 9800 Torch

The KeyEvent can't send to other app.

Hi all,

 

I have implement the A application. At A application,I want send char arrary via EventInjector.KeyEvent  to B application textbox. but result is fail. Please provide suggest for me. thanks a lot.

 

===========================================================

...........

private class KeyEventThread extends Thread {
private String mdata = "";
private boolean _run = true;

   public synchronized void putData(String s) {
         _run = false;
         mdata += s;
         _run = true;
    }

    public synchronized char getChar(){
              if(mdata.length() > 0){
                    try {
                         char c = mdata.charAt(0);
                         mdata = mdata.substring(1);
                         return c;
                    } catch (Exception e) {
                            return '\0';
                    }
              }

              return '\0';
     }

     public void run() {
              for(;:smileywink:{
                     while (_run) {
                              char c = getChar();
                              if(c > 0){
                                    this.send(c);
                               }
                               try {
                                  sleep(15);
                               } catch (Exception e) {
                                     e.printStackTrace();
                               }
                     }
              }
      }

    private void send(char c) {
          EventInjector.KeyEvent pressEndKey2=new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, c,      0);
          EventInjector.invokeEvent(pressEndKey2);
    }
}

 

New Contributor
bertonlu
Posts: 3
Registered: ‎11-18-2012
My Device: 9800 Torch

Re: The KeyEvent can't send to other app.

 

Repost......

 

private class KeyEventThread extends Thread {
		private String mdata = "";
		private boolean _run = true;
		
		public synchronized void putData(String s) {
			_run = false;
			mdata += s;
			_run = true;
		}
		
		public synchronized char getChar(){
			if(mdata.length() > 0){
				try {
					char c = mdata.charAt(0);
					mdata = mdata.substring(1);
					return c;
				} catch (Exception e) {
					return '\0';
				}
			}
			
			return '\0';
		}
		
		public void run() {
			for(;;){
				while (_run) {
					char c = getChar();
					if(c > 0){
						this.send(c);
					}
					try {
						sleep(15);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
		
		private void send(char c){
	  		//System.out.println("send(="+c+")");
	  		EventInjector.KeyEvent pressEndKey2=new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, c, 0);
		  	EventInjector.invokeEvent(pressEndKey2);
		}
	}