Results 1 to 12 of 12
Thread: keystroke event program help
- 05-11-2012, 02:45 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
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
- 05-11-2012, 03:03 PM #2
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.
- 05-11-2012, 04:13 PM #3
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: keystroke event program help
- 05-12-2012, 01:39 AM #5
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
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
- 05-12-2012, 01:42 AM #6
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.
- 05-12-2012, 06:49 PM #7
Re: keystroke event program help
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-12-2012, 07:27 PM #8
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
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)
- 05-12-2012, 07:36 PM #9
Re: keystroke event program help
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.java.lang.ArrayIndexOutOfBoundsException: 5
at TKEY.keyReleased(TKEY.java:96)
Please edit your post and add code tags:
http://www.java-forums.org/misc.php?do=bbcode#codeIf you don't understand my response, don't ignore it, ask a question.
- 05-15-2012, 02:42 PM #10
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
Re: keystroke event program help
how can i fix that
- 05-15-2012, 02:57 PM #11
Re: keystroke event program help
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-15-2012, 03:22 PM #12
Similar Threads
-
Keystroke Biometrics - help!
By ashton in forum AWT / SwingReplies: 2Last Post: 01-11-2011, 11:29 AM -
Keystroke Biometrics - help!
By ashton in forum New To JavaReplies: 4Last Post: 01-11-2011, 08:27 AM -
When would one use the KeyStroke class?
By Lil_Aziz1 in forum New To JavaReplies: 8Last Post: 06-18-2010, 01:28 AM -
More than one KeyStroke (Shortcut) for a JMenuItem
By hannehomuth in forum Advanced JavaReplies: 0Last Post: 07-25-2008, 03:35 PM -
Help with import AWTKeyStroke and swing.KeyStroke
By susan in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 10:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks