var clientId = "1UVb6fiUzC1hyzwT2zvsOcwi";
var clientSecret = "de1XdmFwNKx32NWw3b4LHsPh0AvyyALT";
sp.Sleep(100);
//Create a new Bitmap in memory
var memoryImage = new drawing.System.Drawing.Bitmap(action.Bounds.Width, action.Bounds.Height);
//Create a graphics object associated with the bitmap
var memoryGraphics = drawing.System.Drawing.Graphics.FromImage(memoryImage);
//Copy the screen within the bounding rectangle of the drawn gesture area
//I used a square gesture since that seems more intuitive, but it's not neccessary
memoryGraphics.CopyFromScreen(action.Bounds.X, action.Bounds.Y, 0, 0, action.Bounds.Size);
var ms = new clr.System.IO.MemoryStream();
memoryImage.Save(ms, drawing.System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;
var base64Image = clr.System.Convert.ToBase64String(ms.GetBuffer());
memoryGraphics.Dispose();
memoryImage.Dispose();
ms.Dispose()
var authHost = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret;
var client = new http.System.Net.Http.HttpClient();
var json = client.GetStringAsync(authHost);
var obj = JSON.parse(json.Result);
client.Dispose();
if (obj.access_token) {
var token = obj.access_token;
var ocrHost = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + token;
var request = clr.System.Net.WebRequest.Create(ocrHost);
request.Method = "post";
var encoding = clr.System.Text.Encoding.Default;
var paraString = "image=" + clr.System.Net.WebUtility.UrlEncode(base64Image);
var buffer = encoding.GetBytes(paraString);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
var response = request.GetResponse();
var reader = new clr.System.IO.StreamReader(response.GetResponseStream(), clr.System.Text.Encoding.UTF8);
var result = reader.ReadToEnd();
var json = JSON.parse(result);
var jsonArray = json.words_result;
if (jsonArray) {
var OCRText = "";
for(var i=0; i<jsonArray.length; i++) {
OCRText += jsonArray[i].words
}
if (OCRText.length) {
clip.SetText(OCRText);
clr.System.Media.SystemSounds.Asterisk.Play();
}
}
else {
clip.SetText(result);
}
response.Dispose();
reader.Dispose();
}
//单独显示设置颜色关闭 ×变回原内容颜色会变 不单独显示接着显示太长
/*var info = new DisplayTextInfo();
//info.Title = 'Test';
info.TitleAlignment = 'Center';
info.Message = clip.GetText();
info.MessageAlignment = 'Left';
info.Duration = 2000;
//弹出窗口的透明度,有效范围:0.05 - 1.0(1.0不透明)
info.Opacity = 0.5;
//位置也支持位置,使用此格式指定类型:'100,200'
//类型:topleft,top,topright,right,bottomright,bottom,bottomleft,left
info.Location = 'bottom';
info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font('Segoe UI Semibold', 12);
//info.BackColor = '56,169,255';//'56,169,255'; //也支持 RGBinfo.ForeColor = 'white';
info.BackColor = "105,105,105";
info.Padding = 10;//大小
//如果为true,则始终显示在主屏幕上(除非Location是点类型),
//否则会在手势开始的屏幕上显示
info.UsePrimaryScreen = true;
sp.DisplayText(info);*/
var popupMenuInfoEx = new PopupMenuInfoEx(sp.GetCurrentMousePoint());
var applications = sp_config.Gestures.Where(g => g.Active).OrderBy("MatchCount desc").ToArray();
for (var i = 0; i < applications.Length;i++) {
var appActions = sp_config.Gestures.Where(x => x.Description == applications[i].Description).First().Actions;
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem(applications[i].Description+' '+applications[i].MatchCount, applications[i].Script));
}
sp.ShowPopupMenuEx(popupMenuInfoEx);
统计脚本次数
var popupMenuInfoEx = new PopupMenuInfoEx(sp.GetCurrentMousePoint());
var applications = sp_config.Hotkeys.Where(g => g.Active).OrderBy("MatchCount desc").ToArray();
for (var i = 0; i < applications.Length;i++) {
var appActions = sp_config.Hotkeys.Where(x => x.Description == applications[i].Description).First().Actions;
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem(applications[i].Description+' '+applications[i].MatchCount, applications[i].Script));
}
sp.ShowPopupMenuEx(popupMenuInfoEx);
//Get current culture
var culture = sp.GetCurrentCulture();
//Create input box to prompt selecting a language based on available files
var inputBoxInfo = new InputBoxInfo();
inputBoxInfo.Title = "Change Culture";
inputBoxInfo.Message = "Select an available language below. These are the languages available in the StrokesPlus.net\\Resources folder.";
var files = clr.System.IO.Directory.GetFiles(clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Resources");
for (i=0;i<files.Length;i++)
{
var fi = new FileInfo(files[i]);
var file = fi.Name;
if(file.indexOf("Icons") !== 0) { //Ignore the Icons.resources file
file = file.replace(/resources/ig , "").replace(/\./ig,"");
if(file == "") file = "en-US"; //Since the culture name isn't in the English file name, add it manually
inputBoxInfo.Items.Add(CultureInfo.GetCultureInfo(file).DisplayName + " [" + file + "]");
}
}
inputBoxInfo.Sort = true;
//Show the input box
var res = sp.InputBox(inputBoxInfo);
//If a selection was made, change the culture
if(res != null) {
var n = /\[(.*)\]/i; //Define the regular expression for matching the culture string
var match = n.exec(res); //Get the text between the brackets, e.g. [en-US]
sp.ChangeCulture(match[1]);
}
var devices = sp.AllDevices();
var deviceList = "";
for(var i = 0; i < devices.Count; i++)
{
deviceList += `DeviceID: ${devices[i].DeviceID}
Name: ${devices[i].Name}
Description: ${devices[i].Description}
Status: ${devices[i].Status}
`;
}
// Copy list to clipboard
clip.SetText(deviceList);
// Example to look for a specific device
if(devices.Where(d => d.Name == "Rob's Galaxy Note10").Count() > 0) {
sp.MessageBox("Phone connected!", "Galaxy Phone via Bluetooth");
}