/**
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;
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(100);
				if(Constants.IsPreviousStep){
					Constants.IsPreviousStep=false;
					break;
				}
				else if(Constants.IsNextStep){
					Constants.IsNextStep=false;
					break;
				}
			}
			catch(InterruptedException e){
				e.printStackTrace();
			}
		}
	}

}

@@ -718,17 +718,19 @@
 oBeTyped
-=
+ = 
 textToBe
@@ -734,16 +734,37 @@
 oBeTyped
+.replaceAll(%22%5C%5Cs%22,%22%22)
 ;%0A%09%09this
@@ -776,17 +776,19 @@
 topEvent
-=
+ = 
 desktopE
@@ -811,17 +811,19 @@
 erformed
-=
+ = 
 new Atom
@@ -846,17 +846,19 @@
 ypedText
-=
+ = 
 new Stri
@@ -926,32 +926,112 @@
 veKeyEvent e) %7B%0A
+%09%09if(e.getKeyCode() == NativeKeyEvent.VK_ESCAPE)%7B%0A%09%09%09isPerformed.set(true);%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Override%0A%09
@@ -1149,124 +1149,63 @@
 %7B%0A%09%09
-// TODO: Fix user's typing errors. Use OCR to make sure the user types the required text.%0A%09%09char ch=e.getKeyChar();%0A
+char ch=e.getKeyChar();%0A%09%09if(Character.isLetter(ch))%7B%0A%09
 %09%09ty
@@ -1224,16 +1224,17 @@
 nd(ch);%0A
+%09
 %09%09if(tex
@@ -1288,21 +1288,17 @@
 )))%7B%0A%09%09%09
-this.
+%09
 isPerfor
@@ -1304,32 +1304,37 @@
 rmed.set(true);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A%09@Overri

fix global keybaord listeners