Results 1 to 12 of 12
  1. #1
    sana_22 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default keystroke event program help

    Hi there
    i need a program that record the following time for keystroks
    where user enter a string in textfield and the times that need to be capture are
    the time to press the key and release it
    the the to release the key and pressing the next key
    the time for typing the whole string.
    please help me even with small code

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: keystroke event program help

    What have you tried so far? Do you have a small testing program you could post with your questions?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: keystroke event program help

    You didn't bother to reply to Norm's response on your earlier thread: urgent: I need help with on screen keyboard program with java

    Why should we expect any better behavior this time round?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: keystroke event program help

    Quote Originally Posted by DarrylBurke View Post
    You didn't bother to reply to Norm's response on your earlier thread: urgent: I need help with on screen keyboard program with java

    Why should we expect any better behavior this time round?
    I guess it must not have been that urgent after all.

  5. #5
    sana_22 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: keystroke event program help

    i have done a small code for calcuating the start time and end time but i want that to be stored in arry for the times typing whole string
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Calendar;
    public class TKEY extends JFrame implements KeyListener {
    	private JTextField t=new JTextField(10);
    	private JTextField tt=new JTextField(10);
    	private JTextField ttt=new JTextField(10);
    	private JTextField tttt=new JTextField(10);
    	private JLabel l1=new JLabel("enter the key");
    	private JLabel l2=new JLabel("Keypressed");
    	private JLabel l3=new JLabel("Keyreleased");
    	private JLabel l4=new JLabel("Keytyped");
    	private JPanel p=new JPanel(new FlowLayout());
    	
    	 int kp;
        int kr;
    	int kt;
    	Calendar c;
    
    	public TKEY(){
    		super("wlcome");
    		this.setSize(200,300);
    		p.add(l1);
    		p.add(t);
    		p.add(l2);
    		p.add(tt);
    		p.add(l3);
    		p.add(ttt);
    		p.add(l4);
    		p.add(tttt);
    		
    		this.setContentPane(p);
    		this.setVisible(true);
    		t.addKeyListener(this);
    		
    		
    		
    	}
    	
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		new TKEY();
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void keyPressed(KeyEvent arg0) {
    		c=Calendar.getInstance();
    		kp=c.get(Calendar.MILLISECOND);
    		tt.setText(""+kp);
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void keyReleased(KeyEvent arg0) {
    		c=Calendar.getInstance();
    		kr=c.get(Calendar.MILLISECOND);
    		ttt.setText(""+kr);
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void keyTyped(KeyEvent arg0) {
    		c=Calendar.getInstance();
    		kt=c.get(Calendar.MILLISECOND);
    		tttt.setText(""+kt);
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    Last edited by Norm; 05-12-2012 at 01:42 AM. Reason: added code tags

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: keystroke event program help

    What happens when you execute this program? Does it do what you want? If not, please explain.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: keystroke event program help

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    sana_22 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: keystroke event program help

    the code I provide gives the start time when pressing the key and releasing it and type it
    but i need to calculate the time applying that on an actual string

    I wrote a small program to capture the keystroke timing event which are hold time: time from pressing a key and release it
    flight time: time from pressing one key and pressing the next key.. and the total time to type a string ...I've tried to make it simple but there is some sort of inconveniences where it it is giving me the time to type the whole string is smaller than some other and i got an execption i don't how to deal with that
    here is the code
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Calendar;
    public class TKEY extends JFrame implements KeyListener,ActionListener {
    private JTextField t=new JTextField(10);
    private JTextField tt=new JTextField(10);
    private JTextField ttt=new JTextField(10);
    private JTextField tttt=new JTextField(10);
    private JLabel l1=new JLabel("enter the key");
    private JLabel l2=new JLabel("Keypressed");
    private JLabel l3=new JLabel("Keyreleased");
    private JLabel l4=new JLabel("Keytyped");
    private JPanel p=new JPanel(new FlowLayout());
    private JButton n=new JButton("click");
    int i[]=new int[10];
    long tstart;
    long start = 0;
    long end = 0;
    long delay = 0;
    int length=3;
    long a[]=new long[(2*length)-1];
    // int kr,v;
    //i//nt kt;
    //Calendar c;


    public TKEY(){
    super("wlcome");
    this.setSize(200,300);
    p.add(l1);
    p.add(t);
    p.add(l2);
    p.add(tt);
    p.add(l3);
    p.add(ttt);
    p.add(l4);
    p.add(tttt);
    p.add(n);

    this.setContentPane(p);
    this.setVisible(true);
    t.addKeyListener(this);
    n.addActionListener(this);



    }


    /**
    * @param args
    */
    public static void main(String[] args) {
    new TKEY();
    // TODO Auto-generated method stub

    }

    @Override
    public void keyPressed(KeyEvent arg0) {
    // c=Calendar.getInstance();
    //kp=c.get(Calendar.MILLISECOND);
    //tt.setText(""+kp);
    // TODO Auto-generated method stub
    if(t.getText().length()==1)
    tstart = System.currentTimeMillis();
    delay = start;
    start = System.currentTimeMillis();



    }

    @Override
    public void keyReleased(KeyEvent arg0) {
    //c=Calendar.getInstance();
    // kr=c.get(Calendar.MILLISECOND);
    //ttt.setText(""+kr);
    // TODO Auto-generated method stub
    end = System.currentTimeMillis();
    int pos=(t.getText().length() - 1) * 2;
    if(t.getText().length() <= length) {
    a[pos] = end - start;
    if (pos != 0) {
    a[pos - 1] = start - delay;

    }


    }
    if (t.getText().length() == length){
    // button.setEnabled(true);
    long tend = System.currentTimeMillis();
    a[length * 2-1] = tend-tstart;
    }




    }

    // @Override
    /* public void keyTyped(KeyEvent arg0) {
    c=Calendar.getInstance();
    kt=c.get(Calendar.MILLISECOND);
    tttt.setText(""+kt);
    // TODO Auto-generated method stub

    }*/


    @Override
    public void actionPerformed(ActionEvent arg0) {
    for(int i=0;i<a.length;i++)
    //String t=" "+a[i]+"\t";
    //JOptionPane.showMessageDialog(null, "difference:"+a[i]);
    System.out.println(a[i]+"\n");
    // TODO Auto-generated method stub

    }


    @Override
    public void keyTyped(KeyEvent arg0) {
    // TODO Auto-generated method stub

    }

    }




    and the exception i got is
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
    at TKEY.keyReleased(TKEY.java:96)
    at java.awt.Component.processKeyEvent(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unkn own Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: keystroke event program help

    java.lang.ArrayIndexOutOfBoundsException: 5
    at TKEY.keyReleased(TKEY.java:96)
    At line 96 the index to an array is past the end of the array. Look at line 96 and see why the index used on that line goes past the end of the array.


    Please edit your post and add code tags:
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    sana_22 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: keystroke event program help

    how can i fix that

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,971
    Rep Power
    8

    Default Re: keystroke event program help

    Quote Originally Posted by sana_22 View Post
    how can i fix that
    What have you tried?

    Stop ignoring what people are asking or requesting. Norm has saint-like patience, but you've been pretty rude this entire post. I recommend you go back and re-read what everybody wrote, and follow the advice you've already received.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: keystroke event program help

    Answering this question will tell you how to fix the code:

    why the index used on that line goes past the end of the array.

    Change the code to keep the index inbounds.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Keystroke Biometrics - help!
    By ashton in forum AWT / Swing
    Replies: 2
    Last Post: 01-11-2011, 11:29 AM
  2. Keystroke Biometrics - help!
    By ashton in forum New To Java
    Replies: 4
    Last Post: 01-11-2011, 08:27 AM
  3. When would one use the KeyStroke class?
    By Lil_Aziz1 in forum New To Java
    Replies: 8
    Last Post: 06-18-2010, 01:28 AM
  4. More than one KeyStroke (Shortcut) for a JMenuItem
    By hannehomuth in forum Advanced Java
    Replies: 0
    Last Post: 07-25-2008, 03:35 PM
  5. Replies: 1
    Last Post: 07-29-2007, 10:53 PM

Posting Permissions

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