Skip to content

Instantly share code, notes, and snippets.

@fellypsantos
Last active October 28, 2021 04:45
Show Gist options
  • Save fellypsantos/4cc4eb7c2961de285ad085153aeb218b to your computer and use it in GitHub Desktop.
Save fellypsantos/4cc4eb7c2961de285ad085153aeb218b to your computer and use it in GitHub Desktop.
MacroRecorder c# to convert a street code to full address, number and neighborhood.
/**
Author: [email protected]
Description: C# script to run as a macro inside Macro Recorder program.
It receives a code like "FL" and converts to full address
like "Francisco Lima" house number as default and neighborhood.
*/
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
public class Program
{
[DllImport("user32.dll")]
public static extern void keybd_event(
byte bVk,
byte bScan,
uint dwFlags,
uint dwExtraInfo
);
const uint KEYEVENTF_KEYDOWN = 0x0000; // New definition
const uint KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
const uint KEYEVENTF_KEYUP = 0x0002; //Key up flag
const int VK_LCONTROL = 0xA2;
const int VK_LSHIFT = 0xA0;
const int VK_LEFT = 0x25;
const int VK_TAB = 0x09;
const int VK_F7 = 0x76;
const int VK_HOME = 0x24;
const int VK_END = 0x23;
const int VK_C = 0x43;
const int VK_V = 0x56;
private static void pasteFromClipBoard()
{
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(VK_V, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(VK_V, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
}
private static void pressKey(int keyToPress)
{
keybd_event((byte) keyToPress, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
}
private static void writeText(string text, int delay)
{
Clipboard.SetText (text);
pasteFromClipBoard();
pressKey (VK_TAB);
Thread.Sleep (delay);
}
public static void Main()
{
string letterCode = "";
string streetName = "";
string neighborhood = "";
int delay = 100;
bool filled = true;
bool isCenter = true;
letterCode = Clipboard.GetText().ToUpper();
switch (letterCode)
{
case "SI":
streetName = "SEM INFORMACAO";
break;
case "FL":
streetName = "FRANCISCO LIMA";
break;
case "N2":
streetName = "NOVA DOIS";
break;
case "N3":
streetName = "NOVA TRES";
break;
case "SA":
streetName = "SANTO ANTONIO";
break;
case "SB":
streetName = "SAO BENEDITO";
break;
case "JL":
streetName = "JOSE LEONEL";
break;
case "C":
streetName = "CASTANHEIRA";
break;
case "PI":
streetName = "PRINCESA ISABEL";
break;
case "JP":
streetName = "JOAO PAULO II";
break;
case "AR":
streetName = "ANTONIO RAPOSO TAVARES";
break;
case "FB":
streetName = "FLAVIO BATISTA";
break;
case "GP":
streetName = "GURUPA PUCURUI";
break;
case "CMP":
streetName = "CAPITAO MARINHO PAIVA";
break;
case "CRM":
streetName = "CORONEL RABELO MENDES";
break;
case "X":
streetName = "XINGU";
break;
case "12":
streetName = "DOZE DE OUTUBRO";
break;
case "11":
streetName = "ONZE DE NOVEMBRO";
break;
case "CP":
streetName = "CAPITAO PARA";
break;
case "CPP":
streetName = "CASAS POPULARES";
break;
case "BN":
streetName = "BRASIL NORTE";
break;
case "DD":
streetName = "DICO DIAS";
break;
case "H":
streetName = "HORTO";
break;
case "MJ":
streetName = "RIO MOJU";
isCenter = false;
break;
case "PCR":
streetName = "RIO PUCURUY";
isCenter = false;
break;
case "IPX":
streetName = "RIO IPIXUNA";
isCenter = false;
break;
case "MRR":
streetName = "RIO MARARU";
isCenter = false;
break;
case "BB":
streetName = "RIO BAQUIA BRANCO";
isCenter = false;
break;
case "BP":
streetName = "RIO BAQUIA PRETO";
isCenter = false;
break;
case "B":
streetName = "RIO BAQUIA";
isCenter = false;
break;
case "CRZ":
streetName = "RIO CARRAZEDO";
isCenter = false;
break;
case "MRJ":
streetName = "RIO MARAJOI";
isCenter = false;
break;
case "BC":
streetName = "RIO BACA";
isCenter = false;
break;
case "SRP":
streetName = "RIO SARAPOI";
isCenter = false;
break;
case "GM":
streetName = "GURUPA MIRIM";
isCenter = false;
break;
default:
MessageBox.Show("Nenhum código disponível para " + letterCode);
filled = false;
break;
}
if (filled)
{
writeText (streetName, delay); // Place street name
writeText("0", delay); // Place houuse number
pressKey (VK_TAB); // Ignore Complements
if (isCenter){ neighborhood = "CENTRO"; }
else { neighborhood = "ZONA RURAL"; }
writeText (neighborhood, delay); // Place neighborhood name
pressKey (VK_F7); // Go to next tab
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment