Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Auto-Type Clipboard Text

Description
This macro will type the clipboard text into the currently focused window, instead of pasting it.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
May 25, 2016
Date Last Modified
Dec 2, 2016

Macro Code

using System;
using System.Text;

public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
		BFS.General.ThreadWait(2000);
		StringBuilder sendKeyString = new StringBuilder();
		bool isShiftDown = false;
		foreach(char c in text)
		{
			//smart shift syntax building for letters
			if(char.IsLetter(c) || c == ' ')
			{
				if(char.IsUpper(c) && isShiftDown)
				{
					sendKeyString.Append(c);
					continue;
				}
				
				if(char.IsUpper(c) && !isShiftDown)
				{
					isShiftDown = true;
					sendKeyString.Append("+(").Append(c);
					continue;
				}
				
				if(char.IsLower(c) && isShiftDown)
				{
					isShiftDown = false;
					sendKeyString.Append(')').Append(char.ToUpperInvariant(c));
					continue;
				}
				
				if(char.IsLower(c) && !isShiftDown)
				{
					sendKeyString.Append(char.ToUpperInvariant(c));
					continue;
				}
			}
			
			if(char.IsDigit(c))
			{
				if(isShiftDown)
				{
					isShiftDown = false;
					sendKeyString.Append(')').Append(c);
					continue;
				}
				
				sendKeyString.Append(c);
				continue;
			}
			
			//turn off smart shift here
			if(isShiftDown)
			{
				isShiftDown = false;
				sendKeyString.Append(')');
			}
			
			//this part will only work with en-us keyboards
			switch(c)
			{
				case '~':
					sendKeyString.Append("+(`)");
					break;
				case '!':
					sendKeyString.Append("+(1)");
					break;
				case '@':
					sendKeyString.Append("+(2)");
					break;
				case '#':
					sendKeyString.Append("+(3)");
					break;
				case '$':
					sendKeyString.Append("+(4)");
					break;
				case '%':
					sendKeyString.Append("+(5)");
					break;
				case '^':
					sendKeyString.Append("+(6)");
					break;
				case '&':
					sendKeyString.Append("+(7)");
					break;
				case '*':
					sendKeyString.Append("+(8)");
					break;
				case '(':
					sendKeyString.Append("+(9)");
					break;
				case ')':
					sendKeyString.Append("+(0)");
					break;
				case '_':
					sendKeyString.Append("+(-)");
					break;
				case '+':
					sendKeyString.Append("+(=)");
					break;
				case '{':
					sendKeyString.Append("+([)");
					break;
				case '}':
					sendKeyString.Append("+(])");
					break;
				case '|':
					sendKeyString.Append("+(\\)");
					break;
				case ':':
					sendKeyString.Append("+(;)");
					break;
				case '"':
					sendKeyString.Append("+(')");
					break;
				case '<':
					sendKeyString.Append("+(,)");
					break;
				case '>':
					sendKeyString.Append("+(.)");
					break;
				case '?':
					sendKeyString.Append("+(/)");
					break;				
				default:
					sendKeyString.Append(c);
					break;
			}
		}
		
		BFS.Input.SendKeys(sendKeyString.ToString());
		return text;
	}
}