After setting up your Eclipse Project (see Part One) you can begin programing your game! This part of the tutorial deals with the basics of a Slick Game and how to draw text, shapes, and images.

1. Getting Started

In Eclipse, right-click on ‘src’ in your project and select New > Package. Call it ‘slick.tutorial’. You should see it inside your project:

Note: For those unfamiliar with Java, packages work like folders (they are represented by folders in your file manager). For example, slick.tutorial would appear in your file manager as [workspace]/Slick Tutorial/src/slick/tutorial. Packages inside packages are separated by a period instead of a slash.

Right-click on the package and select New > Class. You should see a window like this:

Type ‘TutorialGame’ into Name.
Enter ‘org.newdawn.slick.BasicGame’ into Superclass.

Tip: You can use Eclipse’s neat Autocomplete here. Just type ‘BasicGame’ in the text-box and press Ctrl-Space. It should put in the rest for you.

Make sure ‘public static void main(String[] args)’ and ‘Constructors from superclass’ is checked.

You should see your new class in the main window, with ‘init’ ‘update’ and ‘render’ automatically added. These methods are necessary for creating a game in Slick.

2. Adding the basics

BasicGame contains all the basics for creating a simple game in Slick. As you can see, there are three main methods that were automatically added. I will explain them.

init is called when the game starts. You can put code here to set things up for your game, such as loading resources like images and sounds.

update is called periodically, usually every 20 milliseconds, but the time will vary depending on how much processing you’ll be putting in. This is where the game logic is done.

render is called constantly. This is where all your graphics is done.

Then there is main. Everything starts here. Let’s put in the first few lines of code to get things going.

Every game needs to be put into a GameContainer to be viewed. We are using AppGameContainer, which puts our game into a window. Place these lines inside the main method:

TutorialGame game = new TutorialGame("Slick Tutorial");
AppGameContainer container = new AppGameContainer(game);
container.start();

AppGameContainer will probably be underlined in red at this point. If it is, you need to add it to your list of imports. Eclipse makes this easy, just click on AppGameContainer in your code and press Ctrl-1. A menu should pop up like this:

Double-click on the first option “Import ‘AppGameContainer’ (org.newdawn.slick)”.

Tip: You can always use Eclipse’s ‘Quick Fix’ (Ctrl-1) whenever there is an error in your code.

There will probably still be an error at new AppGameContainer(game); This is because it throws an exception and we need to place it in a try/catch block. I won’t go into detail about exceptions at this moment. What we will do now is use Quick Fix to automatically surround this piece of code in a try/catch block. Click on the underlined code and press Ctrl-1 then double-click “Surround with try/catch”. It should be the second option. Don’t worry about code underlined in yellow at the moment, those are just harmless warnings.

You main method should look something like this:

public static void main(String[] args) {
     TutorialGame game = new TutorialGame("Slick Tutorial");
     try {
          AppGameContainer container = new AppGameContainer(game);
          container.start();
     } catch (SlickException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
     }
}

Now run this by pressing Ctrl-F11. If you did everything right, you should see a black window pop up showing frames per second in the corner.

3. Saying Hello

Now let’s put a something on the screen. It’s as easy as putting this in your render method:

g.drawString("Hello World!",200,200);

You should see this when you run it:

Now let’s add a bit of color. This is done easily by putting in a g.setColor(Color) before drawing the text. Slick comes with a few preset colors, but there are numerous ways to make your own colors. Here are some examples of ways you can set the color:

g.setColor(Color.red); // Preset Color Red
g.setColor(new Color(0,255,150)); // A  yucky green defined using three integers
g.setColor(new Color(1.0f,0.5f,0.5f,0.8f)); // A light purple with 80% transparency defined using four floats
g.setColor(new Color(0x7b2900)); // A brown-reddish defined using hex

You can also draw various shapes, such as rectangles, ovals and lines, by using g.drawRect(x,y,w,h); g.drawOval(x,y,w,h); and g.drawLine(x1,y1,x2,y2); These methods only draw an outline. You can draw filled objects by using g.fill instead of g.draw (You obviously can’t fill a line, though). There are more shapes you can draw and fill. Experiment with them 🙂

The following code:

g.setColor(new Color(0xff00ff)); // Luminous pink!
g.drawString("Hello World!",200,200);

g.setColor(Color.blue);
g.drawRect(180, 170, 150, 80);

g.setColor(Color.red);
g.drawLine(250, 190, 300, 230);
g.drawLine(250, 230, 300, 190);

g.setColor(new Color(0f,0.6f,0.8f,0.5f)); // transparent bluish, 50% transparent
g.fillOval(190, 180, 60, 60);

Should make this picture:

If you want to smooth the jagged edges, put g.setAntiAlias(true); before everything. You can also apply anti-aliasing to specific things, by turning it on and off before drawing things. For instance, if we wanted the red cross smoothed but leave the circle we would turn on anti-aliasing before drawing the lines and then turn it off before filling the circle.

g.setColor(new Color(0xff00ff)); // Luminous pink!
g.drawString("Hello World!",200,200);

g.setColor(Color.blue);
g.drawRect(180, 170, 150, 80);

g.setAntiAlias(true);
g.setColor(Color.red);
g.drawLine(250, 190, 300, 230);
g.drawLine(250, 230, 300, 190);

g.setAntiAlias(false);
g.setColor(new Color(0f,0.6f,0.8f,0.5f)); // transparent bluish, 50% transparent
g.fillOval(190, 180, 60, 60);

As you can see, text is automatically anti-aliased.

4. Adding Images

I’ve found that slick is much more efficient at drawing images that shapes. I don’t know the technical details, but it’s not a train-smash, as your game will probably use a lot of images and not that much geometry.

For the next bit, we’re going to need some images. For the tutorial I’m going to use the ones pictured below.

First, declare the images before everything else, like this:

public class TutorialGame extends BasicGame {

	Image arrow;
	Image triangle;

	...

Remember, you will need to import Image from Slick. Using Quick Fix, make sure you select the right one (org.newdawn.slick), because there will also be the option to import Image from Java2D (java.awt).

Then, load the resources in the init method. Remember, all resource loading must be done inside init. Make sure your images are in your project folder.

public void init(GameContainer container) throws SlickException {

	arrow = new Image("arrow.png");
	triangle = new Image("triangle.png");

}

Now you can draw the images by simply putting g.drawImage(Image,x,y);in the render method, where x,y is where the top-left corner of your image will be drawn. e.g. g.drawImage(arrow,50,100);

There are some other things you can do with an image, like scaling/stretching it, drawing only parts of it, and changing its color.

Try doing this and see what you get:

// draws the images at the specified positions
g.drawImage(arrow,50,100);
g.drawImage(triangle,100,200);

// draws the image, but with green
g.drawImage(arrow, 150, 100, Color.green);

// To draw the image transparent
// use white as the colour and set the alpha
// the following draws the image at 50% transparency
g.drawImage(arrow, 250, 100, new Color(1f,1f,1f,0.5f));

// draws a part of the image
// a 50x60 snippet at 20,10 on the image
// drawn at 300,200 on the screen
g.drawImage(triangle,
	300, 200, // where you want the top-left of the snippet to be
	350, 260, // bottom-right "
	20, 10, // top-left of the snippet relative to the image
	70, 70); // bottom-right "

// draws the image at twice the size
g.drawImage(arrow,
	50, 350,
	50+arrow.getWidth()*2,
	350+arrow.getHeight()*2,
	0, 0,
	arrow.getWidth(),
	arrow.getHeight());

The snippet there works like this:

You can also stretch the snippet to your liking by changing x2,y2.

It’s usually good practice to place your images and other resources in a ‘res’ folder next to your ‘src’ folder. Then your images will be accessed by new Image("res/imagename.png");

Slick can read a number of image formats, including png, gif and jpg.

This concludes our lesson for today. Next Up we’ll have a look at making things move around in the update method.

This tutorial isn’t really aimed for anyone in particular, but I assume you already know the basics of object orientated programming. If you already use Eclipse for Java development and know your way around it then you can probably skip this one and wait for part two.

For part one you need to have Eclipse for Java developers (download) and the Slick graphics engine (download) that I will be teaching you how to use in the future.

This tutorial requires that you have at least Java 1.5 installed on your system.
To see if you have the correct version Java installed, open a Command Prompt or a Terminal window, type java --version and press enter. If your computer does not recognize the command, then you do not have Java installed. You can download Java here.

Note to Apple users: Mac OS X already has Java installed.

1. Creating a new project in Eclipse.

In Eclipse, click File > New > Java Project. A window like this should appear.

Enter a name (e.g. “Slick Tutorial” or “Clam Chowder Deluxe”). Then click Finish. You should now see your project in the list 🙂

Note: If you do not see a ‘src’ folder, you will have to add it: Right-click on your project, go to Build Path > New Source Folder… type in ‘src’ and click Finish.

2. Adding Slick to your Build Path

Right click on your project and select Build Path > Add Libraries. You should see this:
Select User Library and click Next


Click User Libraries…


Click New… and type in “Slick” and click ok. Now you will have a new entry in the list of User Libraries.


Click on the newly created Slick, click Add JARs… then navigate to where you extracted Slick, go into the ‘lib‘ directory and select lwjgl.jar and slick.jar then click ok.

You should see the jars added to the list:

Now double-click on Native library location under lwjgl.jar, click External Folder… and select the directory you extracted slick (the root, not ‘lib’) and click ok.

Note: By default the root of the Slick folder only contains Windows 32 and 64-bit dll’s. For other systems, look in Slick/lib and find a native jar that matches your system. Extract them into a folder and select that as your native library location.

Next double-click on Javadoc location under slick.jar, click Browse…, navigate to your Slick folder and select javadoc and click ok. Click validate, it should say the location is likely valid. If all is well click ok to go back to the User Libraries window.

Things should look similar to this:

Now click ok, and then make sure “Slick” is checked.

Click Finish. You should now see Slick in your project, like this:

All done !

In the next installment we’ll get started with the code 🙂

Easy Resize Script: Fix

Posted: February 4, 2011 by jellymann in computers, fixes, hotkeys, keyboard, mouse, windows

I forgot something on my last post. The Easy Window Resize script I showed you had the same labels as the original Easy Window Move, so it didn’t work unless you ran them on separate scripts. The simple fix is to rename all the labels to unique ones. Otherwise, you can just use the fixed one below. I replaced all “EWD” with “EWR” and changed all “LButton” to “MButton”.

#MButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWR_MouseStartX, EWR_MouseStartY, EWR_MouseWin
WinGetPos, EWR_OriginalPosX, EWR_OriginalPosY,,, ahk_id %EWR_MouseWin%
WinGet, EWR_WinState, MinMax, ahk_id %EWR_MouseWin%
if EWR_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWR_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWR_WatchMouse:
GetKeyState, EWR_MButtonState, MButton, P
if EWR_MButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWR_WatchMouse, off
return
}
GetKeyState, EWR_EscapeState, Escape, P
if EWR_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWR_WatchMouse, off
WinMove, ahk_id %EWR_MouseWin%,, %EWR_OriginalPosX%, %EWR_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWR_MouseX, EWR_MouseY
WinGetPos, EWR_WinX, EWR_WinY, EWR_WinW, EWR_WinH, ahk_id %EWR_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
if (EWR_MouseX-EWR_WinX) <= (EWR_WinW/3)
{
if (EWR_MouseY-EWR_WinY) <= (EWR_WinH/3)
{
WinMove, ahk_id %EWR_MouseWin%,, EWR_WinX + EWR_MouseX - EWR_MouseStartX, EWR_WinY + EWR_MouseY - EWR_MouseStartY, EWR_WinW + EWR_MouseStartX - EWR_MouseX, EWR_WinH + EWR_MouseStartY - EWR_MouseY
}
else if (EWR_MouseY-EWR_WinY) <= (EWR_WinH/3)*2
{
WinMove, ahk_id %EWR_MouseWin%,, EWR_WinX + EWR_MouseX - EWR_MouseStartX, , EWR_WinW + EWR_MouseStartX - EWR_MouseX,
}
else
{
WinMove, ahk_id %EWR_MouseWin%,, EWR_WinX + EWR_MouseX - EWR_MouseStartX, , EWR_WinW + EWR_MouseStartX - EWR_MouseX, EWR_WinH + EWR_MouseY - EWR_MouseStartY
}
}
else if (EWR_MouseX-EWR_WinX) <= (EWR_WinW/3)*2
{
if (EWR_MouseY-EWR_WinY) <= (EWR_WinH/2)
{
WinMove, ahk_id %EWR_MouseWin%,,, EWR_WinY + EWR_MouseY - EWR_MouseStartY,, EWR_WinH + EWR_MouseStartY - EWR_MouseY
}
else
{
WinMove, ahk_id %EWR_MouseWin%,,,,, EWR_WinH + EWR_MouseY - EWR_MouseStartY
}
}
else
{
if (EWR_MouseY-EWR_WinY) <= (EWR_WinH/3)
{
WinMove, ahk_id %EWR_MouseWin%,,, EWR_WinY + EWR_MouseY - EWR_MouseStartY, EWR_WinW + EWR_MouseX - EWR_MouseStartX, EWR_WinH + EWR_MouseStartY - EWR_MouseY
}
else if (EWR_MouseY-EWR_WinY) <= (EWR_WinH/3)*2
{
WinMove, ahk_id %EWR_MouseWin%,,, , EWR_WinW + EWR_MouseX - EWR_MouseStartX,
}
else
{
WinMove, ahk_id %EWR_MouseWin%,,, , EWR_WinW + EWR_MouseX - EWR_MouseStartX, EWR_WinH + EWR_MouseY - EWR_MouseStartY
}
}
EWR_MouseStartX := EWR_MouseX ; Update for the next timer-call to this subroutine.
EWR_MouseStartY := EWR_MouseY
return

Easy Window Moving and Resizing

Posted: January 29, 2011 by jellymann in computers, hotkeys, keyboard, mouse, windows

Normally, a window can only be dragged by clicking on its title bar. This script extends that so that any point inside a window can be dragged while holding down a modifier, in this case the Windows key. This is a slightly modified version of this script, and I mentioned it in one of my previous AutoHotkey posts.

#LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return

Gnome windows can also be resized using a modifier+middle mouse button. So to have that functionality in windows, I tweaked the above script a little bit. First, since I’m not very familiar with AHK, I studied the script for a few minutes to find out where all the action lies. I discovered the line that does the actual moving based on all the information collected from user input, etc:

WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY

This means: Move the window (WinMove) that’s under the mouse (ahk_id %EWD_MouseWin%) to position (X,Y), which is the original position of the window (EWD_WinX,EWD_WinY) plus the distance moved by the mouse, which is the position of the mouse (EWD_MouseX,EWD_MouseY) subtracted by the position of the mouse before it was moved (EWD_MouseStartX,EWD_MouseStartY).

Now all I had to do was replace that code with new code that resizes the window instead of moving it. The WinMove function above is taking three arguments, the window to be moved, X and Y. To resize a window, all one has to do is add width and height at the end of the function, so it would be something like this:

WinMove, window, x, y, width, height

The tricky thing about resizing is that the window must resize in a different direction depending on what region of the window the mouse is in. The following image shows where these regions are:

Basically, the window is cut into thirds vertically, then the two side regions are cut into thirds again horizontally, and the center is cut in half horizontally. I used a bunch of nested if-statements to check which region the mouse cursor is and then move/resize the window accordingly. I’m not sure if it is the best way, but it works. Here is that part of the script:

if (EWD_MouseX-EWD_WinX) <= (EWD_WinW/3)
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY, EWD_WinW + EWD_MouseStartX - EWD_MouseX, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)*2
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, , EWD_WinW + EWD_MouseStartX - EWD_MouseX,
}
else
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, , EWD_WinW + EWD_MouseStartX - EWD_MouseX, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}
else if (EWD_MouseX-EWD_WinX) <= (EWD_WinW/3)*2
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/2)
{
WinMove, ahk_id %EWD_MouseWin%,,, EWD_WinY + EWD_MouseY - EWD_MouseStartY,, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else
{
WinMove, ahk_id %EWD_MouseWin%,,,,, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}
else
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)
{
WinMove, ahk_id %EWD_MouseWin%,,, EWD_WinY + EWD_MouseY - EWD_MouseStartY, EWD_WinW + EWD_MouseX - EWD_MouseStartX, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)*2
{
WinMove, ahk_id %EWD_MouseWin%,,, , EWD_WinW + EWD_MouseX - EWD_MouseStartX,
}
else
{
WinMove, ahk_id %EWD_MouseWin%,,, , EWD_WinW + EWD_MouseX - EWD_MouseStartX, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}

The second thing I changed what what mouse button to use. There are two places where this has to change:

The first line #LButton:: must be changed to #MButton:: to use the middle button for resizing.

Then, a few lines down, after EWD_WatchMouse:, there is the line which checks if the mouse button is down: GetKeyState, EWD_LButtonState, LButton, P. All we do is change LButton to MButton, so it looks like this: GetKeyState, EWD_LButtonState, MButton, P. I didn’t bother with changing EWD_LButtonState because that’s just a variable name, and when I did try change it, and all other instances of it, the script stopped working, so I just left it.

And here is the finished script:
[UPDATE] This script doesn’t work with the Easy Window Move script unless it is separate. My next post has a simple fix for that.

#MButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, MButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY, EWD_WinW, EWD_WinH, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
if (EWD_MouseX-EWD_WinX) <= (EWD_WinW/3)
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY, EWD_WinW + EWD_MouseStartX - EWD_MouseX, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)*2
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, , EWD_WinW + EWD_MouseStartX - EWD_MouseX,
}
else
{
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, , EWD_WinW + EWD_MouseStartX - EWD_MouseX, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}
else if (EWD_MouseX-EWD_WinX) <= (EWD_WinW/3)*2
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/2)
{
WinMove, ahk_id %EWD_MouseWin%,,, EWD_WinY + EWD_MouseY - EWD_MouseStartY,, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else
{
WinMove, ahk_id %EWD_MouseWin%,,,,, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}
else
{
if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)
{
WinMove, ahk_id %EWD_MouseWin%,,, EWD_WinY + EWD_MouseY - EWD_MouseStartY, EWD_WinW + EWD_MouseX - EWD_MouseStartX, EWD_WinH + EWD_MouseStartY - EWD_MouseY
}
else if (EWD_MouseY-EWD_WinY) <= (EWD_WinH/3)*2
{
WinMove, ahk_id %EWD_MouseWin%,,, , EWD_WinW + EWD_MouseX - EWD_MouseStartX,
}
else
{
WinMove, ahk_id %EWD_MouseWin%,,, , EWD_WinW + EWD_MouseX - EWD_MouseStartX, EWD_WinH + EWD_MouseY - EWD_MouseStartY
}
}
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return

My Escape key stopped working today. After freaking out for a few minutes about where I’m going to get the money to buy a new keyboard, I made a quick AHK script that remaps the Caps Lock key to Escape. Then I realised that I would probably tap it by accident doing some irreversible damage while typing, so I thought I’d remap Scroll Lock to Escape (Who uses scroll lock, anyway?):

ScrollLock::
{
Send {Esc}
return
}

On the topic of Caps Lock, everyone know how annoying it is when you accidentally press it and your wall post’s mood changes significantly. SERIOUSLY ANNOYING. So here is how to remap the Caps Lock key to something else. In this case, it acts as a third Control key:

CapsLock::Ctrl

If you sometimes do need to use the Caps Lock, like when you’re flaming a forum, or coding a serious error message, you can map Shift+Caps Lock to toggle Caps Lock. I tried doing it like this, which is the way most people did it in the foums:

+CapsLock::CapsLock

But unfortunately that only turned Caps Lock on and not off. And since my Caps Lock key is remapped to Control, I couldn’t turn it off without killing the AHK script.

The following script does work, as it checks the state of Caps Lock and then acts accordingly:

+CapsLock::
{
if GetKeyState("Capslock", "T")
SetCapsLockState, Off
else
SetCapsLockState, On
return
}

I’ve always wanted my scroll wheel to be an easy volume-control, as my keyboard does not have media keys. I Googled and went through forum after forum to find out what AHK commands control volume, but none of them worked right. Then today I stumbled across something. The media keys are keyboard keys after all, and can be mapped and remapped in AHK just like any other, even if your keyboard doesn’t have them. Here is a simple script that uses the scroll wheel and middle mouse button to change and mute the volume:

#MButton::Volume_Mute
#WheelDown::Volume_Down
#WheelUp::Volume_Up

When in doubt, consult the AutoHotkey Key List.
I also recommend you also take a look at my other post on AutoHotkey.

Retrostyle Arcade Tech Demo #1

Posted: January 24, 2011 by jellymann in computers, gaming, java, programming

So sorry I never got you screenshots of the game earlier, so I’ve decided to make up for it by giving you guys a video!

Enjoy 🙂

Inception, Part 3…

Posted: January 23, 2011 by jellymann in computers, CPU, inception, linux, ubuntu, virtualisation

… and probably the last one. I tried again this week with Virtual PC and I ran into similar problems.

the reason, I think, is because my fail processor doesn’t support this kind of hard-core virtualisation, so I might have to wait until I get a Core i# with Hardware Virtualisation before I consider part 4 at all.

Anyway, thanks for the interest 🙂 All I got accomplished so far was install five different operating systems inside one: Ubuntu, OpenSUSE, Fedora, Windows XP and Windows 7. My computer is going to die soon, I guess…

Looks it, too