[Java] Opening CD drive
Moderator: MaxCoderz Staff
[Java] Opening CD drive
Is there an easy way to open the CD drive of a computer using java?
Not that it serves any particular purpose or anything. My plan is to create another annoying program with it (hey, I've got to keep myself entertained in compsci somehow!).
Speaking of annoying programs, I may release my ALT+TAB program, which presses alt+tab randomly (every couple of minutes or so). There's got to be somebody out that that would find it useful!
Not that it serves any particular purpose or anything. My plan is to create another annoying program with it (hey, I've got to keep myself entertained in compsci somehow!).
Speaking of annoying programs, I may release my ALT+TAB program, which presses alt+tab randomly (every couple of minutes or so). There's got to be somebody out that that would find it useful!
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
Under Windows, at least, you could use MCI control strings to do this (check the platform SDK - MCIWNDM_EJECT) but I don't know what Java's stance on what the CLI calls P/Invoke is, given Java's write-once-run-on-anything stance.
- Captain_America
- New Member
- Posts: 25
- Joined: Wed 27 Sep, 2006 10:18 pm
- elfprince13
- Sir Posts-A-Lot
- Posts: 234
- Joined: Sun 11 Dec, 2005 2:21 am
- Contact:
there is no platform independent way of doing it in java. sorry. on a side note, I have some fun, mayhem causing code:
[edit]
code updated for more fun
Code: Select all
import java.awt.*;
import java.util.*;
import java.awt.event.*;
class Robo{
static int oldx = 0;
static int oldy = 0;
static int newx = 0;
static int newy = 0;
static Toolkit tk = Toolkit.getDefaultToolkit();
static final int width = tk.getScreenSize().width;
static final int height = tk.getScreenSize().height;
public static void main(String[] args) throws Exception{
Robot robo = new Robot();
Random r = new Random(System.currentTimeMillis());
for(int I = 0; I<50; I++){
oldx = MouseInfo.getPointerInfo().getLocation().x;
oldy = MouseInfo.getPointerInfo().getLocation().y;
newx = r.nextInt(width);
newy = r.nextInt(height);
int xdist = Math.abs(oldx - newx);
int ydist = Math.abs(oldy - newy);
int destdist = (int)Math.sqrt(Math.pow(xdist,2)+Math.pow(ydist,2));
for(int i = 0; i<destdist; i++){
robo.mouseMove((int)(xdist/destdist),(int)(ydist/destdist) );
}
robo.delay(250);
robo.mousePress(InputEvent.BUTTON1_MASK);
robo.mouseRelease(InputEvent.BUTTON1_MASK);
}
robo.keyPress(KeyEvent.VK_SHIFT);
robo.keyPress(KeyEvent.VK_CONTROL);
robo.keyPress(KeyEvent.VK_ESCAPE);
robo.keyRelease(KeyEvent.VK_SHIFT);
robo.keyRelease(KeyEvent.VK_CONTROL);
robo.keyRelease(KeyEvent.VK_ESCAPE);
}
}
code updated for more fun
Last edited by elfprince13 on Tue 19 Dec, 2006 10:46 pm, edited 1 time in total.
- Captain_America
- New Member
- Posts: 25
- Joined: Wed 27 Sep, 2006 10:18 pm
How about I just give you a jar file that you can execute?
I couldn't find the tab one, but I did fix my screen-flipping program:
http://eric.woodtx.com/coding/annoying.jar
Enjoy!
I couldn't find the tab one, but I did fix my screen-flipping program:
http://eric.woodtx.com/coding/annoying.jar
Enjoy!
- Captain_America
- New Member
- Posts: 25
- Joined: Wed 27 Sep, 2006 10:18 pm
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
Not since Microsoft stopped shipping it. If you're running an old version of Windows, you might well have it, but I find it rather unlikely. No school or work machines I've ever used have had it installed.
In any case, you can download it from here.
In any case, you can download it from here.
School computers *never* have any stuff installed. I've found that most people have it installed because certain applications needed it, sometimes even for websites.
If only windows shipped with stuff like that...too bad it's bloated with other crap! Unix distros manage to include Java, Python, and many other runtime environments and still aren't as bloated.
If only windows shipped with stuff like that...too bad it's bloated with other crap! Unix distros manage to include Java, Python, and many other runtime environments and still aren't as bloated.