Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
This script uses the default Snipping Tool that started in Win+Shift+S on Win10 instead of the gesture trail then shows it on the screen. You can replace the Chinese program title and shortcut in line 8 and line 2. Shows on the screen based on Enhanced sp.ShowImage, and it can be zoomed in/out by stroll, saved by right click, closed by double-click, moved. There are two for you to choose from. The first one is the total code, when you right click the picture to save it, it will pop up the fold after click the context menu "Save File".
Code:var startimage = clip.GetImage();
sp.SendModifiedVKeys([vk.LSHIFT,vk.LWIN], [vk.VK_S]);
sp.Sleep(10);
for(i=0; i< 6000; i++) {
//ScreenClippingHost
sp.Sleep(1000);
var wnd = sp.WindowsFromTitlePartial("屏幕截图");
var currimage = clip.GetImage();
if(i > 0 && wnd.Count() === 0 && clip.ContainsImage()) {
ShowImage(clip.GetImage(), action.End,1);
function ShowImage(img, pt, border) {
if (img == null) return;
var Forms = forms.System.Windows.Forms;
if (border == null) border = 0;
if (border != 0) { pt = new Point(pt.X - border, pt.Y - border); }
var form = new Forms.Form;
form.StartPosition = Forms.FormStartPosition.Manual;
form.FormBorderStyle = (border != 0) ?
Forms.FormBorderStyle.None :
Forms.FormBorderStyle.SizableToolWindow ;
form.TopMost = true;
form.ControlBox = false;
form.ShowInTaskbar = false;
form.Margin = new Forms.Padding(0);
if (border != 0) { form.Padding = new Forms.Padding(border); }
form.MinimumSize = new Size(10, 10);
form.Size = new Size(10, 10);
form.Location = pt;
form.AutoSize = true;
form.GetType().GetProperty("DoubleBuffered",
host.flags(clr.System.Reflection.BindingFlags.NonPublic,
clr.System.Reflection.BindingFlags.Instance))
.SetValue(form, true);
form.BackColor = drawing.System.Drawing.SystemColors.HotTrack;
var pic = new Forms.PictureBox;
pic.Name = 'pic';
pic.SizeMode = Forms.PictureBoxSizeMode.Zoom;
pic.Size = new Size(img.Width, img.Height);
pic.BackColor = drawing.System.Drawing.SystemColors.Control;
if (border != 0) { pic.Location = new Point(border, border); }
pic.Image = img;
form.Controls.Add(pic);
var autoSize = form.Size;
var t = (form.ClientSize.Width - pic.Width - form.Padding.Horizontal);
autoSize.Width -= t;
autoSize.Height -= t;
form.AutoSize = false;
form.Size = autoSize;
pic.Dock = Forms.DockStyle.Fill;
var form_shown =
form.Shown.connect(
function (sender, args) {
form.TopMost = true;
form.Activate();
if(sp.IsKeyToggled(vk.CAPITAL)){
sp.SendVKey(vk.CAPITAL);
}
});
var pic_doubleClick =
pic.DoubleClick.connect(
function (sender, args) {
form.Close();
});
menuBlind = ShowImageBindAllMenu(form, pic);
dragMoveBlind = ShowImageBindDragMove(form, pic);
wheelResizeBlind = ShowImageBindWheelResize(form, pic);
Forms.Application.Run(form);
}
function ShowImageBindWheelResize(form, pic) {
var form_mouseWheel =
form.MouseWheel.connect(
function (sender, e) {
var factor = e.Delta / 1000;
var ampt = forms.System.Windows.Forms.Control.MousePosition;
var rmpt = new Point();
rmpt.X = ampt.X - form.Left;
rmpt.Y = ampt.Y - form.Top;
var intFunc = Math.floor;
rmpt.X += intFunc(rmpt.X * factor);
rmpt.Y += intFunc(rmpt.Y * factor);
form.SetBounds(ampt.X - rmpt.X, ampt.Y - rmpt.Y,
form.Width + intFunc(form.Width * factor),
form.Height + intFunc(form.Height * factor));
});
return [form_mouseWheel];
}
function ShowImageBindAllMenu(form, pic) {
var Forms = forms.System.Windows.Forms;
var contextMenu1 = new Forms.ContextMenu();
var menu1 = contextMenu1.MenuItems.Add("Save File");
// item 1
var saveFileDialog1 = new Forms.SaveFileDialog();
saveFileDialog1.Filter = "png files (*.png)|*.png" ;
saveFileDialog1.RestoreDirectory = true ;
saveFileDialog1.FileName = clr.System.DateTime.Now.ToString().replace(/[/\*?":<>| ]/g, '_');
var menu1_click = menu1.Click.connect(function (sender, e) {
if (saveFileDialog1.ShowDialog() == Forms.DialogResult.OK) {
pic.Image.Save(saveFileDialog1.FileName, drawing.System.Drawing.Imaging.ImageFormat.Png);
}
});
pic.ContextMenu = contextMenu1;
return [menu1_click];
}
function ShowImageBindDragMove(form, pic) {
var Cursors = forms.System.Windows.Forms.Cursors;
var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");
var pic_mouseMove =
pic.MouseMove.connect(
function (sender, e) {
var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
var cursor = hitResize ? Cursors.SizeNWSE : Cursors.Default;
if (pic.Cursor != cursor) pic.Cursor = cursor;
if (e.Button == MouseButtons.Left) {
ReleaseCapture.Invoke(null, null);
sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
hitResize ? 0xF008 : 0xF012, 0);
}
});
return [pic_mouseMove];
}
break;
}
}
The second one is that use sp.DisplayImage() directly or add to the ShowImageWithMenu plugin that Rob provides. It will pop up the fold after right click the image.
Code:var startimage = clip.GetImage();
sp.SendModifiedVKeys([vk.LSHIFT,vk.LWIN], [vk.VK_S]);
sp.Sleep(10);
for(i=0; i< 6000; i++) {
//ScreenClippingHost
sp.Sleep(1000);
var wnd = sp.WindowsFromTitlePartial("屏幕截图");
var currimage = clip.GetImage();
if(i > 0 && wnd.Count() === 0 && clip.ContainsImage()) {
sp.DisplayImage(clip.GetImage(), true);
//ImageWithMenu.Show(clip.GetImage(), action.Start, 0);
break;
}
}
The following is the demo: Edited by user Saturday, March 5, 2022 9:50:59 AM(UTC)
| Reason: Update the time between the snip ends and the image shows, and add a demo
|
1 user thanked soooulp for this useful post.
|
|