Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ScreenShot_tool
- {
- class NonStaticMain
- {
- [DllImport("user32.dll")]
- static extern short GetAsyncKeyState(int vKey);
- public static bool IsKeyPushedDown(Keys vKey)
- {
- return 0 != (GetAsyncKeyState((int)vKey) & 0x8000);
- }
- public NonStaticMain()
- {
- while (true)
- {
- bool GotScreenShot = false;
- int image_X = 0;//X Location
- int image_Y = 0;//Y Location
- int image_W = 0;//Width
- int image_H = 0;//Height
- int originalX = Cursor.Position.X;
- int originalY = Cursor.Position.Y;
- while (IsKeyPushedDown(Keys.LButton))
- {
- Rectangle rect = new Rectangle();
- rect.X = Cursor.Position.X;
- rect.Y = Cursor.Position.Y;
- Pen pen = new Pen(Color.Gray);
- using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
- {
- int currentX = Cursor.Position.X;
- int currentY = Cursor.Position.Y;
- //I'm sure t there's a more eficent way to do this. I'm just shit with maths.(I know it's not even complex maths :o)
- #region my shitty maths for drawing a dragable rectangle
- if (currentX >= originalX && currentY >= originalY)//bottom right
- {
- image_X = originalX;
- image_Y = originalY;
- image_W = (currentX - originalX);
- image_H = (currentY - originalY);
- }
- else if (currentX <= originalX && currentY <= originalY)//upper left
- {
- image_X = currentX;
- image_Y = currentY;
- image_W = (originalX - currentX);
- image_H = (originalY - currentY);
- }
- else if (currentX <= originalX)//bottom left
- {
- image_X = currentX;
- image_Y = originalY;
- image_W = (originalX - currentX);
- image_H = (currentY - originalY);
- }
- else if (currentY <= originalY)//top right
- {
- image_X = originalX;
- image_Y = currentY;
- image_W = (currentX - originalX);
- image_H = (originalY - currentY);
- }
- graphics.DrawRectangle(
- pen,
- image_X,
- image_Y,
- image_W,
- image_H);
- #endregion
- }
- GotScreenShot = true;
- }
- if (GotScreenShot)
- {
- using (Bitmap bitmap = new Bitmap(image_W, image_H))
- {
- using (Graphics graphics = Graphics.FromImage(bitmap))
- {
- graphics.CopyFromScreen(image_X, image_Y, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy);
- uploadScreenShot(bitmap);
- }
- }
- break;
- }
- Thread.Sleep(30);
- }
- }
- void uploadScreenShot(Bitmap image)
- {
- //cba adding upload code rn, so I'll just save it :P
- string baseDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\screenshots";
- if (!Directory.Exists(baseDirectory))
- Directory.CreateDirectory(baseDirectory);
- string fileLocation = baseDirectory + "\\" + randomString() + ".png";
- image.Save(fileLocation, System.Drawing.Imaging.ImageFormat.Png);
- Process.Start(baseDirectory);
- }
- string randomString()
- {
- //Will return a random byte array in a string, cba making any other shit
- Random rand = new Random();
- string result = null;
- for (int i = 0; i < rand.Next(20, 40); i++)
- result += ((byte)rand.Next(0, 255)).ToString("X");
- return result;
- }
- }
- }
- #region old code
- /*if (currentX >= originalX && currentY >= originalY)//bottom right
- {
- graphics.DrawRectangle(
- pen,
- originalX,
- originalY,
- (currentX - originalX),
- (currentY - originalY));
- }
- else if (currentX <= originalX && currentY <= originalY)//upper left
- {
- graphics.DrawRectangle(
- pen,
- currentX,
- currentY,
- (originalX - currentX),
- (originalY - currentY));
- }
- else if (currentX <= originalX)//bottom left
- {
- graphics.DrawRectangle(
- pen,
- currentX,
- originalY,
- (originalX - currentX),
- (currentY - originalY));
- }
- else if (currentY <= originalY)//top right
- {
- graphics.DrawRectangle(
- pen,
- originalX,
- currentY,
- (currentX - originalX),
- (originalY - currentY));
- }*/
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement