AutoHotkey Community

It is currently May 27th, 2012, 8:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Screenshot Hotkey
PostPosted: July 26th, 2006, 12:46 am 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
This script uses Irfanview's command line options to create a screenshot and then automatically save it to a specified directory, with the filename including a timestamp. It is based off of the script found here.

The template structure based off of toralf's template.ahk.

I cleaned up the base script and added in the functionality that comes with toralf's template.

Please let me know what you think, as this is my first time posting a script.

Update: I have updated this script to 1.3.2 based on user comments, as noted in the ChangeLog in the script.

Code:
; Script Name:   ScreenShot Hotkey
; Version:   v1.3.2
; Author:   silveredge78
;
; This script uses Irfanview's command line options to create a screenshot
; and then automatically save it to a specified directory, with the filename
; including a timestamp.
;
; It is based off of the script found at
; http://www.ghisler.ch/wiki/index.php/AutoHotkey:_Make_a_Screenshot_of_the_current_Window_with_Irfanview
;
; Template structure based off of toralf's template.ahk found at
; http://www.autohotkey.com/forum/topic7551.html
;
; Changelog:
; v1.3.2, 09/17/07
; - Added checking for SS_Ext to be JPG or TIF, and if so to allow for a default save quality/compression.
; - Added variable SS_JPG and SS_TIF to set the default save quality/compression, declared in the function.
;   - TIF Compression levels: 0 - None, 1 - LZW, 2 - Packbits, 3 - Fax3, 4 - Fax4, 5 = Huffman, 6 - JPG, 7 - ZIP
; - Added SS_Extra to allow for the extra parameter to be passed in the command line call.
;
; v1.3.1, 08/07/07
; - Moved SS_Folder, SS_IView, SS_Ext variables back to inside of TakeScreenshot() function to allow for
;   use as an include
;
; v1.3.0, 08/03/07
; - Cleaned up script structure to be more consistent
; - Moved SS_Folder, SS_IView to variable declaration section
;   - Adjusted Capture function to look for those as global variables
; - Added SS_Ext variable for easy changing of file type
; - Adjusted TrayTip function to report what file type it is captured using.
;
; v1.2.1, 01/24/07
; - Adjusted filename to be HHMM.SS instead of HH.MM.SS.
;
; v1.2.0, 08/10/06
; - Added traytips to notify the user that the capture completed.
;
; v1.1.1, 08/04/06
; - Changed SS_Folder to open minimized directly rather than after opening
; - Added pause before opening SS_Folder to allow capture to finish to prevent incorrect capture
;
; v1.1.0, 08/01/06
; - Added FolderOpen function to check for whether SS_Folder is open & if not, open & minimize the folder
; - Commented out function for !Printscreen so as to not bypass normal screen capture ability
; - Added variable for SS_IView, for easier setting of Iview32.exe location
; - Moved declaration of SS_Folder and SS_IView to beginning of TakeScreenshot function
;
; v1.0.0, 07/25/06
; - Added ability to use variants of PrintScreen to be used to capture
;   desktop, window, client area
; - Cleaned up original script to run via a function
; - Added in system variables for less manual configuration of folders

;********** Settings, variable declarations **********

#SingleInstance Force
OnExit, quit

ProgramName = Screenshot Hotkey
programVersion = 1.3.2
programFullName = %ProgramName% v%programVersion%
programAuthor = silveredge78

;********** Auto-execute section **********

; set representative icon - DEBUG: optional
Menu, Tray, Icon, Shell32.dll, 95, 1
; process command line parameters
GoSub, getParams
; construct tray menu - DEBUG: optional
GoSub, trayMenu
; end of auto-execute section
Return

;********** hotkeys **********

^Printscreen::   ; [Ctrl]+[PrintScreen]
  CapMethod = 0   ; Takes a screenshot of the whole desktop
  TakeScreenshot(CapMethod)
Return

^!Printscreen::   ; [Ctrl]+[Alt]+[PrintScreen]
  CapMethod = 1   ; Takes a screenshot of the active window
  TakeScreenshot(CapMethod)
Return

/*
!PrintScreen::   ; [Alt]+[PrintScreen]
  CapMethod = 2   ; Takes a screenshot of the client area
  TakeScreenshot(CapMethod)
Return

!Esc::      ; [ALT]+[ESC]: terminate script
  Suspend ; exempt from suspension - DEBUG: optional
  GoSub, quit
Return
*/

;********** Functions **********
; Function to capture screenshot
TakeScreenshot(CapMethod)
{
  SS_Folder = C:\screenshot               ; Sets the folder to save in
  SS_IView = %A_ProgramFiles%\IrfanView\i_view32.exe      ; Sets the location of Irfanview
  SS_Ext = jpg                     ; Sets the extension (file type) to save with
  SS_JPG = 100                     ; Sets the default JPG save quality (0-100)
  SS_TIF = 0                     ; Sets the default TIF compression level

  IfNotExist, %SS_Folder%               ; Checks if the folder exists
    FileCreateDir, %SS_Folder%               ; If it doesn't, it creates it

  FormatTime, TimeStamp,A_now,yyyy-MM-dd_HHmm.ss      ; Formats the current timestamp for naming purposes

  If SS_Ext = jpg
    SS_Extra = /jpgq=%SS_JPG%               ; Sets the extra command line for JPG
  Else If SS_EXT = tif
    SS_Extra = /tifc=%SS_TIF%               ; Sets the extra command line for TIF

  ; Runs Irfanview via command line, using capture method selected by hotkey, & filetype specified above.
  Run, %SS_IView% "/capture=%CapMethod% /convert=%SS_Folder%\screenshot-%TimeStamp%.%SS_Ext% %SS_Extra%"
  Sleep 1000
  FolderOpen(SS_Folder)
  InfoTrayTip(CapMethod,SS_Ext)
}

; Function to popup tray tip, notifying user what kind of capture was made
InfoTrayTip(CapMethod,SS_Ext)
{
  If CapMethod = 1
    Tip = Active Window
  Else
    Tip = Desktop
  TrayTip,%ProgramName%, %Tip% captured as %SS_Ext%,,1
  SetTimer, RemoveTrayTip, 2000
}

; Function to check if SS_Folder is open or not, if not, it will open & minimize
FolderOpen(SS_Folder)
{
  IfWinExist, %SS_Folder%
    Return
  Else
    Run, %SS_Folder%, , Min
}

;********** Subroutines **********
   
RemoveTrayTip:
  SetTimer, RemoveTrayTip, Off
  TrayTip
Return

; construct tray menu - DEBUG: optional
trayMenu:
  ; disable standard menu items
  Menu, Tray, NoStandard
  ; show info message
  Menu, Tray, Add, &About, About
  ; separator
  Menu, Tray, Add
  ; terminate script
  Menu, Tray, Add, &Quit, quit
Return

; process command line parameters
getParams:
  If 0 > 0
  {
    Loop, %0% ; for each parameter
    {
      param := %A_Index%
      ; check for switches
      StringLeft, paramType, param, 1
      If paramType = - ; switch indicator
      {
        ; determine type of switch
        StringMid, switch, param, 2, 1
        ; switch
        If switch = x ; DEBUG: template (replace "x")
        {
          ; access value (= next parameter)
          param = % A_Index + 1
          var_x := %param% ; DEBUG: template (replace "var_x")
          MsgBox, var_x:`n%var_x% ; DEBUG: template (replace "var_x")
        }
      }
    }
  }
Return

; Show info message - DEBUG: toDo
About:
  MsgBox, 64, %programFullName%,
  ( LTrim Join
  %programFullName%`n
  Author: %programAuthor%`n
  `n
  This script uses Irfanview's command line options to create a screenshot`n
  and then automatically save it to a specified directory, with the filename`n
  including a timestamp.`n
  `n
  Use [Ctrl]+[PrintScreen] to take a screenshot of the whole desktop.`n
  Use [Ctrl]+[Alt]+[PrintScreen] to take a screenshot of the active window.`n
  `n
  Use [ALT]+[ESC] to terminate the program.
  )
Return

; Terminate script
Quit:
  ExitApp
Return


Last edited by silveredge78 on September 20th, 2007, 8:23 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 7:59 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
BTW: the template is done by Ace_noOne, not by me.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2006, 11:44 pm 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
This idea is repeating ;)

For those who dont want to deploy/use i_view but do it with pure ahk and no includes. By using DC and PrintWindow, you can even make Screenshots of windows behind others. Eg. Invisible Windows. (You could screenshot your Browser even if its behind others windows, etc.)

http://www.autohotkey.com/forum/viewtopic.php?t=12012


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2007, 8:26 am 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Updated the script to my latest the latest version, v1.3.2. I updated the code in the original post. Here is the changelog from the last posted version.

Changelog:
v1.3.2, 09/17/07
- Added checking for SS_Ext to be JPG or TIF, and if so to allow for a default save quality/compression.
- Added variable SS_JPG and SS_TIF to set the default save quality/compression, declared in the function.
- - TIF Compression levels: 0 - None, 1 - LZW, 2 - Packbits, 3 - Fax3, 4 - Fax4, 5 = Huffman, 6 - JPG, 7 - ZIP
- Added SS_Extra to allow for the extra parameter to be passed in the command line call.

v1.3.1, 08/07/07
- Moved SS_Folder, SS_IView, SS_Ext variables back to inside of TakeScreenshot() function to allow for use as an include

v1.3.0, 08/03/07
- Cleaned up script structure to be more consistent
- Moved SS_Folder, SS_IView to variable declaration section
- - Adjusted Capture function to look for those as global variables
- Added SS_Ext variable for easy changing of file type
- Adjusted TrayTip function to report what file type it is captured using.

v1.2.1, 01/24/07
- Adjusted filename to be HHMM.SS instead of HH.MM.SS.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2010, 8:56 pm 
Offline

Joined: October 29th, 2006, 4:09 am
Posts: 39
Location: A2 MI
Using this, and it works great for my needs :) (And ya, old thread, but old tools are cool :P )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2011, 9:37 pm 
Offline

Joined: August 14th, 2009, 3:11 am
Posts: 2
A small correction needs to be made in order for this script to work with the most recent version of Irfanview. The capture mode parameters have changed:

capture values:
0 = whole screen
1 = current monitor
2 = foreground window
3 = foreground window - client area
4 = rectangle selection
5 = object selected with the mouse
6 = start in capture mode (can't be combined with other commandline options)

Therefore I used 0 and 2.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 18th, 2011, 5:18 am 
Offline

Joined: July 15th, 2011, 11:49 pm
Posts: 52
install Windows program
http://www.webtree.ca/newlife/printkey_info.htm
Press PRINT key. Select. I prefer it to IrfanView.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 15th, 2012, 7:22 pm 
Offline

Joined: October 28th, 2010, 12:34 pm
Posts: 76
what do I change to save as png?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 15th, 2012, 8:30 pm 
Using Tic's gdip it is only a few codelines to get screenimage to file.

You need gdip.ahk in the same directory as the program.You can find it here:
http://www.autohotkey.com/forum/topic32238.html


Code:
#include gdip.ahk   ;you need this library in same dir http://www.autohotkey.com/forum/topic32238.html
outfile=screengrab.png  ;change extension to have another fileformat example : image.bmp

PrintScreen:: ;or any other hotkey
pToken := Gdip_Startup()

pBitmap := Gdip_BitmapFromScreen( )
Gdip_SaveBitmapToFile(pBitmap, outfile) 
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Aravind and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group