How to take Screenshot ( Same as Printscreen, just faster) With Hotkey! - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: How to take Screenshot ( Same as Printscreen, just faster) With Hotkey! (/Thread-How-to-take-Screenshot-Same-as-Printscreen-just-faster-With-Hotkey) |
How to take Screenshot ( Same as Printscreen, just faster) With Hotkey! - Eternity - 08-18-2013 I'm was working on an All-in-one application for my laptop since I'm starting school tomorrow and i wanted to share the code here just in case anyone was interested. The hotkey works outside of the focused window, meaning it will work with whatever you're using. [code=vb] Public Class Form1 Public ImageData As Image Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Integer Public TakeScreenshotViaHotkey As Boolean = True Sub TakeScreenShot() Dim Bounds As Rectangle Dim CapturedImg As System.Drawing.Bitmap Dim GFX As Graphics Bounds = Screen.PrimaryScreen.Bounds CapturedImg = New System.Drawing.Bitmap(Bounds.Width, Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb) GFX = Graphics.FromImage(CapturedImg) GFX.CopyFromScreen(Bounds.X, Bounds.Y, 0, 0, Bounds.Size, CopyPixelOperation.SourceCopy) ImageData = CapturedImg SaveScreenShot() End Sub Sub SaveScreenShot() 'Start of BMP format SaveFileDialog1.DefaultExt = "*.bmp" SaveFileDialog1.Filter = "Bitmap Images|*.bmp" SaveFileDialog1.ShowDialog() Try ImageData.Save(SaveFileDialog1.FileName) Catch ex As Exception MessageBox.Show("An error has occured while saving" & vbNewLine & "And i don't know what's wrong.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Bouton1_Click(sender As Object, e As EventArgs) Handles Bouton1.Click TakeScreenShot() End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Update_Stuff.Tick ' When the printscreen button is pressed it will run the "TakeScreenshot" sub. If TakeScreenshotViaHotkey = False Then If GetKeyPress(Keys.PrintScreen) Then TakeScreenShot() End If End If End Sub Private Sub Hotkey_Checkbox_Click(sender As Object, e As EventArgs) Handles Hotkey_Checkbox.Click 'Enables and disable the ability to use the hotkey. If Hotkey_Checkbox.Checked = True Then TakeScreenshotViaHotkey = True Else TakeScreenshotViaHotkey = False End If End Sub End Class [/code] Credits: Not 100 % mine. RE: How to take Screenshot ( Same as Printscreen, just faster) With Hotkey! - Xanii - 08-19-2013 That's pretty cool. I think that for people trying to learn more about this, a good project would be to add more file types and other features like: auto-upload, etc. Thanks for sharing! RE: How to take Screenshot ( Same as Printscreen, just faster) With Hotkey! - Eternity - 08-19-2013 (08-19-2013, 08:39 PM)Xanii Wrote: That's pretty cool. I think that for people trying to learn more about this, a good project would be to add more file types and other features like: auto-upload, etc. Doubt I'll do that since the Imgur API isn't much of a challenge, but maybe |