3

I want to replace a keyboard entry (CTRL PrntSc) with a mouse click (launching a batchfile). I know that there are SEND and SENDKEY codes but have not been able to make the code

Send("^{Printscreen}")

trigger the right effect.

AutoIT and AutoHotKey may be able to do it, but if the above can work, it seems simpler.

Press Keyboard keys using a batch file deals with a similar question in THIS forum i.e. with making a batchfile first open a program and then send keystrokes to it, but that looks complex and I need guidance in extracting the code for merely sending a batchfile hotkey command.

https://www.donationcoder.com/forum/index.php?topic=25389.0 Suggests the use of NirCMD and AutoIT as well as AutoHotKey and Macro Express. I have experience with the last two - but would need help with all four.

First comment (from Daniel Wisehart) I'm using Windows 10 - I hope that answers the PLATFORM query. I have already quoted the (ineffective) code of my batchfile. There are NO error messages. However the desired effect of the mouse cursor becoming Greenshot-cross-hairs did not eventuate. . Second comment (from Aacini) - thanks for your correction. Replacing "^{Printscreen}" with "^PRTSC" did not make the required difference. The mouse cursor still does not change to a cross-hairs.

I have tried the sample batch file in the 3rd comment (by Hackoo) - which seems extremely complex for just a conversion from a hotkey to a mouse click. It triggers a (blue, NOT black), 'DOS' window saying that "The screen can not be set to the number of lines and columns specified.' Then the text disappears and a little later the window closes. What is that code ? VB, Visual Basic, VBS, something else ?

  • 1
    What platform are you working on? Best if you come up with your own batch file, include it here and add what problems you are seeing with any error messages: http://stackoverflow.com/help/mcve – Daniel Wisehart Sep 16 '16 at 16:51
  • 1
    The right string for Ctrl-PrintSc is `"^PRTSC"` accordingly to a link given at the question in your first link... – Aacini Sep 16 '16 at 16:56

1 Answers1

2

Just give a try for this batch file (-_°)

/*
@echo off & cls & color 1E 
Mode con Cols=15 lines=5
::Autor Delmar Grande
::http://bbat.forumeiro.com/t248-bat-exe-printscreen-usando-vb-net
::Data  Qui 11 Jul 2013
:: Modified by Hackoo on 09/09/2016 to save image with system date
title PrintScreen by Delmar Grande and modified by Hackoo
Rem Just adding a little timeout to organise our screenshot
Timeout /T 4 /Nobreak>nul
findstr "'%skip%VB" "%~f0" > "%tmp%\%~n0.vb"
for /F %%i in ('dir /B /S ^"%WinDir%\Microsoft.NET\Framework\vbc.exe^"') do set "vbc=%%i"
if /i "%vbc%"=="" cls & color 1c & echo This script needs the framework & pause & Exit
cls
%vbc% /nologo /out:"%tmp%\%~n0.exe" "%tmp%\%~n0.vb"
"%tmp%\%~n0.exe"
del "%tmp%\%~n0.vb" >NUL 2>&1
del "%tmp%\%~n0.exe" >NUL 2>&1
exit
*/
Imports System.Windows.Forms 'VB
Module ModulePrintscreen 'VB
    Sub Main() 'VB
        Dim MaDate As String 'VB
        SendKeys.SendWait("{%}({PRTSC})") 'VB
        If My.Computer.Clipboard.ContainsImage() Then 'VB
            MaDate = Format(Now,"dd-MM-yyyy_hh-mm-ss") 'VB
            My.Computer.Clipboard.GetImage.Save(MaDate & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 'VB
        End If 'VB
    End Sub 'VB
End Module 'VB
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 1
    I may have misunderstood the instructions, and so posted my reply to the suggestions as an Edit. I reacted to all three replies. – Joseph Philippa Sep 19 '16 at 08:04