• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

background process

 
Ranch Hand
Posts: 39
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to run a background process in java and how to trap keyboard events?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does background or parallel processing on threads. See the Sun Concurrency Tutorial for a great intro to threads. The ranch has a whole Thread forum if you want to follow up with questions.

We don't so much "trap" keyboard events as "respond" to them. Are you working in Swing? The Sun Swing Tutorial has a section on event listeners. Again there is a dedicated forum for Swing that may be more helpful.

Are you working on a particular problem? The ranch works really well if you can post some code that almost works. Then we know where you're stuck and what to try next.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're wanting to trap keyboard events destined for another application (i.e. not the Java application that you're writing), I don't think Pure Java can help. Each individual operating system may, or may not, provide hooks, but you'd have to access them with native code and/or external programs.

If that is indeed what you want to do, then I hope it's for legitimate reasons. I can think of plenty of nasty reasons for wanting to get hold of other apps' keystrokes, but not all that many nice ones...
 
Rajasekhar Pentakota
Ranch Hand
Posts: 39
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
import java.lang.*;
import java.util.Scanner;
public class demonthread {

public static void main(String[] args) {
Thread12 w=new Thread12();
//w.start();
}
}

class Thread12 extends Thread
{
FileWriter f;
Label l;
Scanner sc;
public Thread12()
{
try
{
f=new FileWriter("xyz1.txt",true);
l=new Label();

int i=0;
while(true)
{
l.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent ke)
{

try
{
f.append("hello--");
f.flush();
}
catch(IOException ex){}
finally
{
try
{
f.close();
}
catch(Exception ex){}
}
}
});

}
}
catch(IOException ie){ie.printStackTrace();}
catch(Exception ex){}
finally
{
try
{
f.close();
}
catch(Exception ex){}
}

}

public void run()
{
}
}




I am trying to write a key logger. can any body help.. how to run a process continuously ? and another thing , what should be the object the keyboardlistener should refer?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I am trying to write a key logger.

these steps might be the easiest way
- post your email address on several web pages
- wait for the spam to hit
- open only the ones with attachments
- study the source code
 
reply
    Bookmark Topic Watch Topic
  • New Topic