public void keyPressed() { 
		
		// the length of time in the current frame.
		//int lgth=timeLineObject.displayEnd-timeLineObject.displayStart;
		//println("keypress:"+keyCode+" key:"+key+"keyInt: "+(int)key);
		Event event=getLastEvent();
		// for testing event place when moving.
		Event testEvent=getLastEvent();
		// selection just for last event i.e if nothing selected use this
		Vector eventSelection=new Vector();
		eventSelection.add(event);
		timeLineObject.sortSelection();
		if ( keyCode == ESC ) {System.out.println("escpressed");}
		if ( keyCode == SHIFT ) {shift=true;}//slidersDraw.setYPosShiftPressed(mouseY);
		if ( keyCode == CONTROL ) {ctrl=true;}
		if ( keyCode == ALT ) {alt=true;}
		if ( key == CODED ) { 
			if (shift) {
				// get interval to move by.
				int interval=timeLineObject.quantize;
				if (ctrl && alt) {interval=timeLineObject.quantize*timeLineObject.beatLength*timeLineObject.beatPerBar;}
				else if (ctrl) {interval=timeLineObject.quantize*timeLineObject.beatLength;}
				else if (alt) {interval=1;} 
				
				switch(keyCode) {
				case RIGHT: // move last Selected event to the right.
					if (timeLineObject.selection.size()>0) {
						testEvent=(Event) timeLineObject.selection.get( timeLineObject.selection.size()-1);
						eventSelection=timeLineObject.selection;
					}
					if ((testEvent!=null) && (testEvent.eventTime+interval<=timeLineObject.timeLineLength)) {
						moveEvents(eventSelection,interval);
					} 
					break;
				case LEFT: // move last Selected event to the left.
					if (timeLineObject.selection.size()>0) {
						testEvent=(Event) timeLineObject.selection.get(0);
						eventSelection=timeLineObject.selection;
					}
					if ((testEvent!=null) && (testEvent.eventTime-interval>=0)) {
						moveEvents(eventSelection,-1*interval);
					}
					break;
				} 
			}  // if (shift) 
			else if ((!"".equals(inputMode) && ctrl) || ("".equals(inputMode))) {// if not in input mode lft, right select event - if in inoput mode the ctrl +left,right selectes event
				switch(keyCode) {
				case RIGHT: 
					if (timeLineObject.lastSelEvent<timeLineObject.timeLine.size()) {    	
						timeLineObject.currentEvent=timeLineObject.lastSelEvent+1;   
						
					}  else {      	timeLineObject.currentEvent=timeLineObject.timeLine.size()-1;       }
					
					if (event!=null && event.eventTime>timeLineObject.displayEnd) {
						int lgth=timeLineObject.displayEnd-timeLineObject.displayStart;
						scrollRight((int)event.eventTime-timeLineObject.displayEnd+Math.round(lgth*0.2f));
					}
					break;
				case LEFT: 
					if (timeLineObject.lastSelEvent>0){
						timeLineObject.currentEvent=timeLineObject.lastSelEvent-1;
						
					}
					if (event!=null && event.eventTime<timeLineObject.displayStart) {
						int lgth=timeLineObject.displayEnd-timeLineObject.displayStart;
						scrollLeft((int)timeLineObject.displayStart-(int)event.eventTime+Math.round(lgth*0.2f));
					}
					break;
				default:break;
				}
			}// if  (shift) else 
		}
		
		if (inputMode.equals("")){
			//if (keyCode!=17) {
			//	int i=key;
			//}
			System.out.println(((int)key)+":"+key);
			cursorPos=0;
			keyFunctionMap(key, alt);
			cursorPos=inputStr.length();
		}
		else {
			println("input:"+key);
			if ( keyCode == ENTER ){ processInput();}
			else if ( key == 3 ) {      	copyInputStrToClip();	        }
			else if ( key == 22 ) {      		pasteClipToInput();        }
			else if ( keyCode == TAB || keyCode == -1 ){inputMode="";inputStr="";}//exit input mode.
			else if ( keyCode == BACKSPACE ){
				if (shift) {inputStr=inputStr.substring(cursorPos,inputStr.length());cursorPos=0;}// erase input str
				else if (alt) {// erase inputstr back to last slash.
					int pos = inputStr.lastIndexOf("\\");
					if (pos==-1) {pos = inputStr.lastIndexOf("/");}
					if (pos > -1) {
						inputStr=inputStr.substring(0,pos+1);
						cursorPos=inputStr.length();
					}
				} else {
					if ((inputStr.length()>0) && (cursorPos>0)) {inputStr=inputStr.substring(0,cursorPos-1)+inputStr.substring(cursorPos,inputStr.length());cursorPos --;}// ersae last char in inputStr
					else {inputMode="";inputStr="";}// exit input mode
				}
			} else if ( keyCode == DELETE ){
					if ((inputStr.length()>0) && (cursorPos<inputStr.length()-1)) {inputStr=inputStr.substring(0,cursorPos)+inputStr.substring(cursorPos+1,inputStr.length());}// ersae last char in inputStr
			} else if ( keyCode == UP )  {

				 if ("vfFi".indexOf(inputMode)>-1) {//last file
					inputStr=getFileName(inputStr,-1);
					//send preview if wav file
					if (inputStr.toLowerCase().indexOf(".wav")>inputStr.length()-5) {sendPreview();}
					//cursorPos=inputStr.length();
				} 
				else if ("=".equals(inputMode)) {
					inputStr=midiUtil.changeControlMap(inputStr,-1);
					//cursorPos=inputStr.length();
				}
				
			}   else if ( keyCode == DOWN ) {

				if ("vfFi".indexOf(inputMode)>-1) {//next file
					inputStr=getFileName(inputStr,1);
					if (inputStr.toLowerCase().indexOf(".wav")>inputStr.length()-5) {sendPreview();}
					//cursorPos=inputStr.length();
				} 
				else if ("=".equals(inputMode)) {
					inputStr=midiUtil.changeControlMap(inputStr,1);
					//cursorPos=inputStr.length();
				}
				
			} else if (!ctrl && keyCode == LEFT ) {// note ctrl+LEFT && ctrl+ RIGHT to move cursor as left and right are caught above to select event
				if (cursorPos>0) {cursorPos--;}
				if (alt) {cursorPos=0;}
			} else if (!ctrl && keyCode == RIGHT ) {
				if (cursorPos<inputStr.length()) {cursorPos++;}
				if (alt) {cursorPos=inputStr.length();}
			}  else if (keyCode>=32) { 
				if (cursorPos>inputStr.length()) {cursorPos=inputStr.length();}
				inputStr=inputStr.substring(0,cursorPos)+(char)key+inputStr.substring(cursorPos,inputStr.length());cursorPos ++;
			}
		}
	}