Jump to content

Problem with a hotkey


berto
 Share

Recommended Posts

Hy, ive made a little application a while ago, runs fine but i want to implement something new.The application automatically saves images created with the PrtScr key in JPEG format in its native directory, but now i want to somehow make my software run as a process or a service, and to autodetect when the PrtScr key has been pressed, and when this happens to automatically execute its default action to retrieve the image from clipboard, and save it as JPEG in its default directory.

The problem is that i cant make it work, the screeshots are not saved, something is not being executed, can someone help me a bit with the code here ?

heres the code

; Script Start - Add your code below here

#Include <Clipboard.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>
#include <WinAPI.au3>

HotKeySet("(PRINTSCREEN)", "a1");setting hotkey and when pressed it calls function a1 wich actually execute the printscreen
; 
Func a1()
    Send("(PRINTSCREEN)")
    Call("print")
EndFunc
; after the key was intercepted and passed to the OS, the screenshot was createt
Func print() 
        $check = _Clipboard_IsFormatAvailable ($CF_BITMAP)
    If $check = True Then
        $Filename = @ScriptDir & "\Image.jpg"
        $count = 0
        While FileExists($Filename)
            $count += 1
            $Filename = @ScriptDir & "\Image" & $count & ".jpg"
        WEnd
        $ps = _Clipboard_GetData ($CF_BITMAP)
        _ScreenCapture_SetJPGQuality (100)
        _ScreenCapture_SaveImage ($Filename, $ps)
    EndIf
EndFunc
While 1
   Sleep (100)
Wend

Thank You and sorry for my bad english and Ohh,

this is the old one wich works perfectly, it works by double clicking on the exe after a screenshot was taken by pressing the PrtScr key, and thats the thing i want to remove : the need to double click the exe.

; Script Start - Add your code below here
;; Save bitmap to file
#include <A3LClipboard.au3>
#include <A3LScreenCap.au3>
$check = _Clip_IsFormatAvailable ($CF_BITMAP)
If $check = True Then
    $Filename = @ScriptDir & "\Image.jpg"
    $count = 0
    While FileExists($Filename)
        $count += 1
        $Filename = @ScriptDir & "\Image" & $count & ".jpg"
    WEnd
    $ps = _Clip_GetData ($CF_BITMAP)
    _ScreenCap_SetJPGQuality (100)
    _ScreenCap_SaveImage ($Filename, $ps)
EndIf
If $check = False Then
    MsgBox(0, "Info", "Nu ai nici un screenshot in clipboard") ; translated means You Don't Have Any Screenshots In The Clipboard
    Exit
EndIf
Edited by berto
Link to comment
Share on other sites

first thing I see is that the HotKeySet() line needs to be:

HotKeySet("{PRINTSCREEN}", "a1")

not

HotKeySet("(PRINTSCREEN)", "a1")

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

use the Screencapture Function from Au3Lib instead of the one of Windows

The Hotkey overwrites the Default function :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

This works for me

HotKeySet("{PRINTSCREEN}", "al")
While 1
    Sleep(100)
WEnd
Func al()
    HotKeySet("{PRINTSCREEN}")
    Send("{PRINTSCREEN}")
    HotKeySet("{PRINTSCREEN}", "al")
    MsgBox(0,"","PrintScreen Pushed")
EndFunc   ;==>al

Without turning the HotKey off you were creating an infinite loop because the Send caused the function to do another send over and over again.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...