public void writeToStream(PrintStream p) {

		// create definition string with first character 1 if the
		// mapping is character-defined, 0 otherwise
		String definition = "" + (characterDef ? 1 : 0);

		// add character or keycode
		definition += "\t";
		if (characterDef)
			definition += (int) keyChar;
		else
			definition += keyCode;

		// add key location
		definition += "\t" + keyLocation;
		definition += "\t0x" + Integer.toHexString(scancode);

		// build and add modifiers as a set of flags in an integer value
		int modifiers = 0;
		modifiers |= (shiftDown ? FLAG_SHIFT : 0);
		modifiers |= (ctrlDown ? FLAG_CTRL : 0);
		modifiers |= (altDown ? FLAG_ALT : 0);
		modifiers |= (capslockDown ? FLAG_CAPSLOCK : 0);
		definition += "\t" + modifiers;

		// add additional information if available (and necessary)
		if (!characterDef)
			definition += "\t" + KeyEvent.getKeyText(this.keyCode);

		// output the definition to the specified stream
		p.println(definition);
	}