Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

API to track clipboard changes ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any API which will notify me (Listener) whenever any changes occurs at system clipboard ?
I already know a method (by using Timer) to track clipboard changes but I think if i check for clipboard's data at 100ms then lots of CPU (which has just single core) time will be wasted
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FlavorListener?
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:FlavorListener?

i tried this but i guess, this listener only listens to the data flavour for eg: if i copy image using ctrl-c then listener gets invoked but when i again copy another image this time listener doesn't invoke
please run the code and check out whats happening , All I wanted to track is clipboard changes no matter what data is in clipboard but when ever user performs any copy operation i should get notification , is there a way (I know using Timer but it will consume lot of CPU)
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> but when i again copy another image this time listener doesn't invoke

seems to work if the clipboard contents are cleared, but then there'd be nothing to paste

might be easier, provided there's not a lot of text components, to just override copy(),
and put a notification in there.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Dunn wrote:
seems to work if the clipboard contents are cleared, but then there'd be nothing to paste

lolzzz

Michael Dunn wrote:
might be easier, provided there's not a lot of text components, to just override copy(),
and put a notification in there.

I didn't get what you are saying please elaborate ....
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all text components inherit
cut() copy() paste()
from JTextComponent

you can override those methods, to do a number of things

run this, copy "Hello World", now try to paste it into the 2nd textField,
and again into the 3rd textField

same applies to cut() and copy()
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh! I m soory i guess you are not getting my requirement I want to monitor each & every thing which sits in system clipboard
so for eg :
if you copy a .exe into clipboard i should get notified that something has copied into clipboard (No matter what it is...)
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Java's not really a good choice for writing spyware. You need a less well-behaved language for that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic