File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to capture the delete key? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to capture the delete key?" Watch "How to capture the delete key?" New topic
Author

How to capture the delete key?

danish shaikh
Greenhorn

Joined: Nov 09, 2004
Posts: 21
Hi All,
I m creating an TextEditor having the track changes feature as in MSWord 2003 ie whenever i make ne changes in the document the changes r highlighted with different color.... also whenever i delete some words it shud be displayed as striked out... this is working for backspace key but not for the delete key... if have used ke.consume() function to capture the delete/backspace key event... its works fine for backspace but not for delete... so plz do the needful its very urgent...

Looking for ur reply...

Regards,
danish shaikh.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Add a KeyListener. Use KeyEvent.getKeyCode() == KeyEvent.VK_DELETE to trap when the delete key is pressed.
D.
danish shaikh
Greenhorn

Joined: Nov 09, 2004
Posts: 21
Hi,
Thanks for reply, but i have already used the same logic but it is not working my logic is:--

public void keyPressed (KeyEvent ke)
{
int code=ke.getKeyCode();
if(code==KeyEvent.VK_DELETE && flag==true)
consume=true;// used to consumed the key in the keytyped event
}

thanks
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
works for me. Are you sure flag isn't false ?
danish shaikh
Greenhorn

Joined: Nov 09, 2004
Posts: 21
Hi,,
thanks for reply.
i m damm sure that the flag will become false.
flag is used to check the existing file is selected or not (true).
The same logic is used for backspace but its working ...
public void keyPressed(KeyEvent ke)
{
int code=ke.getKeyCode();
if(code==KeyEvent.VK_BACK_SPACE && flag==true)
consume=true;
}

thnks in advance,
Bye.Regards,
Danish Shaikh
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
I suggest you debug your code. Print out the value of code and flag in your keyPressed method - what is printed ?
D.
danish shaikh
Greenhorn

Joined: Nov 09, 2004
Posts: 21
how to debug the code i m using Textpad as n editor ...
so i dont know how to do debugging..

Thanks.
Bye,
Regards,
Danish Shaikh
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
You add calls to System.out.println and run the code.
D.
 
Consider Paul's rocket mass heater.
 
subject: How to capture the delete key?
 
Similar Threads
How to track backspace key?
Backspace/Delete not working in Unix environment
capturing enter key in netscape 6.01?
Text box qs
sunil