• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to capture the delete key?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a KeyListener. Use KeyEvent.getKeyCode() == KeyEvent.VK_DELETE to trap when the delete key is pressed.
D.
 
danish shaikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
works for me. Are you sure flag isn't false ?
 
danish shaikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You add calls to System.out.println and run the code.
D.
 
Greenhorn
Posts: 1
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found in my debugging

(1) That I needed to add my action listener to the component I'm listening to... (I always forget this)
(2) I need to use KeyEvent.VK_DELETE == e.getKeyChar() instead of KeyEvent.VK_DELETE == e.getKeyCode()

Then it worked for me.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Some new people wait a long time before posting; I think the longest I have seen is a full ten years. But you have gone the other way, finding the solution after eleven years!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While we are on the topic of listening to key input, the recommended way is to use Key bindings
reply
    Bookmark Topic Watch Topic
  • New Topic