/**
Khalid
*/
package org.sikuli.slides.listeners;

import java.util.concurrent.atomic.AtomicBoolean;

import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.sikuli.api.ScreenRegion;
import org.sikuli.slides.utils.Constants.DesktopEvent;

public class GlobalKeyboardListeners implements NativeKeyListener, Runnable{
	private ScreenRegion region;
	private String textToBeTyped;
	private DesktopEvent desktopEvent;
	private AtomicBoolean isPerformed;
	private StringBuilder typedText;
	public GlobalKeyboardListeners(ScreenRegion region, String textToBeTyped, DesktopEvent desktopEvent){
		this.region=region;
		this.textToBeTyped=textToBeTyped;
		this.desktopEvent=desktopEvent;
		this.isPerformed=new AtomicBoolean();
		typedText=new StringBuilder();
	}
	@Override
	public void nativeKeyPressed(NativeKeyEvent e) {
	}

	@Override
	public void nativeKeyReleased(NativeKeyEvent e) {
	}

	@Override
	public void nativeKeyTyped(NativeKeyEvent e) {
		// TODO: Fix user's typing errors. Use OCR to make sure the user types the required text.
		char ch=e.getKeyChar();
		typedText.append(ch);
		if(textToBeTyped.equalsIgnoreCase(typedText.toString())){
			this.isPerformed.set(true);
		}
	}

	@Override
	public void run() {
		while(!isPerformed.get()){
			try{
				Thread.sleep(1000);
			}
			catch(InterruptedException e){
				e.printStackTrace();
			}
		}
	}

}

@@ -231,16 +231,58 @@
 Region;%0A
+import org.sikuli.slides.utils.Constants;%0A
 import o
@@ -1368,12 +1368,186 @@
 (100
-0
 );%0A
+%09%09%09%09if(Constants.IsPreviousStep)%7B%0A%09%09%09%09%09Constants.IsPreviousStep=false;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%09else if(Constants.IsNextStep)%7B%0A%09%09%09%09%09Constants.IsNextStep=false;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A
 %09%09%09%7D

fix skipping steps in tutorial mode