TOOD Posted January 19, 2021 Share Posted January 19, 2021 Hey, I'd like to do an action with the button DEL then send DEL This what I started with Local $sString = StringReplace(_NowDate(), "/", "-") Func _Start() _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") Send("{DEL}") EndFunc ;==>_Start But it end up in a loop So I looked online and I found a function with _IsPressed, it doesn't end up in a loop which is great, but the function isn't working. HotKeySet("1", "one") Func one() HotKeySet("1") $dll = DllOpen("user32.dll") While _IsPressed(31) _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") Send("1") Sleep(1) If Not _IsPressed(31) Then ExitLoop WEnd DllClose($dll) HotKeySet("1", "One") EndFunc ;==>one Button 1 is registering normally but the screen capture function isn't working. _WinAPI_Keybd_Event(0x2E, 0) Sleep(8) _WinAPI_Keybd_Event(0x2E, 2) Interestingly, swapping "1" with "{DEL}" doesn't even send the button DEL. I also tried the del button with win api, the del button still isn't being sent. I am really confused. I just want to take a screenshot with date and time every time I press delete. Link to comment Share on other sites More sharing options...
Davidowicza Posted January 19, 2021 Share Posted January 19, 2021 This worked for me: #include <Date.au3> #include <ScreenCapture.au3> HotKeySet("1", "one") HotKeySet("{ESC}","leave") While 1 Sleep(50) WEnd Func one() _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") HotKeySet("1") Send("1") Sleep(200) HotKeySet("1", "one") EndFunc Func leave() Exit EndFunc TOOD 1 Link to comment Share on other sites More sharing options...
TOOD Posted January 19, 2021 Author Share Posted January 19, 2021 It worked perfectly, thank you so much! Link to comment Share on other sites More sharing options...
therks Posted January 19, 2021 Share Posted January 19, 2021 This can't be the entire script obviously, cus this would just run and exit. Not sure why you're using DllOpen without using the open handle in anything, perhaps you misunderstand what that function is for? Anyway, I wrote this up: #include <Date.au3> #include <Misc.au3> #include <ScreenCapture.au3> Global $hUser32 = DllOpen('user32.dll') OnAutoItExitRegister(_Exit) While 1 If _IsPressed('2E', $hUser32) Then _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") Sleep(100) EndIf WEnd Func _Exit() DllClose($hUser32) EndFunc TOOD 1 My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
TOOD Posted January 19, 2021 Author Share Posted January 19, 2021 3 minutes ago, therks said: This can't be the entire script obviously, cus this would just run and exit. Not sure why you're using DllOpen without using the open handle in anything, perhaps you misunderstand what that function is for? Anyway, I wrote this up: #include <Date.au3> #include <Misc.au3> #include <ScreenCapture.au3> Global $hUser32 = DllOpen('user32.dll') OnAutoItExitRegister(_Exit) While 1 If _IsPressed('2E', $hUser32) Then _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") Sleep(100) EndIf WEnd Func _Exit() DllClose($hUser32) EndFunc This also worked perfectly. Thank you guys so much! therks 1 Link to comment Share on other sites More sharing options...
TOOD Posted January 19, 2021 Author Share Posted January 19, 2021 48 minutes ago, therks said: This can't be the entire script obviously, cus this would just run and exit. Not sure why you're using DllOpen without using the open handle in anything, perhaps you misunderstand what that function is for? Anyway, I wrote this up: #include <Date.au3> #include <Misc.au3> #include <ScreenCapture.au3> Global $hUser32 = DllOpen('user32.dll') OnAutoItExitRegister(_Exit) While 1 If _IsPressed('2E', $hUser32) Then _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") Sleep(100) EndIf WEnd Func _Exit() DllClose($hUser32) EndFunc Hey, unfortunately, I wasn't paying too much attention I want to capture the screen first and THEN send the DEL key. Link to comment Share on other sites More sharing options...
TOOD Posted January 19, 2021 Author Share Posted January 19, 2021 1 hour ago, Davidowicza said: This worked for me: #include <Date.au3> #include <ScreenCapture.au3> HotKeySet("1", "one") HotKeySet("{ESC}","leave") While 1 Sleep(50) WEnd Func one() _ScreenCapture_Capture(@DesktopDir & "\" & StringRegExpReplace(_Now(), '[/ :]', '-') & ".jpg") HotKeySet("1") Send("1") Sleep(200) HotKeySet("1", "one") EndFunc Func leave() Exit EndFunc I swapped the "1" with DEL to fit my case, and while it worked on my computer, testing it on another computer sends two deletes instead of one. Any idea why ? Link to comment Share on other sites More sharing options...
pixelsearch Posted January 19, 2021 Share Posted January 19, 2021 Hi Tood, what about this ? HotKeySet("{DEL}", "_Start") ... Func _Start() HotKeySet("{DEL}") ; unset so DEL key can be sent during the function _ScreenCapture_Capture(...) Send("{DEL}") HotKeySet("{DEL}", "_Start") ; set before leaving the function EndFunc ;==>_Start therks 1 Link to comment Share on other sites More sharing options...
Davidowicza Posted January 19, 2021 Share Posted January 19, 2021 Throwing the unset before the screen capture as @pixelsearch said could help as sending the the key immediately after could be a timing issue which could explain why your other computer is sending 2 deletes. If that is still an issue, throw a short sleep(100) after the unset of the hotkey. Link to comment Share on other sites More sharing options...
pixelsearch Posted January 19, 2021 Share Posted January 19, 2021 Thank you @Davidowicza I didn't realise that you sent a similar solution with Send("1") Throwing the unset should always be the very 1st instruction in the function (and resetting it should be the last one) to avoid several calls to the HotkeySet function. I like to compare this precaution to a similar one when we use _IsPressed : If _IsPressed("01", $hDll) Then While _IsPressed("01", $hDll) Sleep(10) Wend ... Reviewing some old scripts, I realise that sometimes I used both ways in the same HotkeySet function. I don't remember why I did it like that in the script below, maybe because the unsetting wasn't the 1st instruction : HotKeySet("{NUMPAD8}", "_8_Tab_Prec") ... Func _8_Tab_Prec() If WinActive(" - Opera") Then HotKeySet("{NUMPAD8}") ; désactiver Hotkey 8 While _IsPressed("68", $hDll) ; 68 = touche 8 du clavier numérique Sleep(10) Wend ... HotKeySet("{NUMPAD8}", "_8_Tab_Prec") ; réactiver Hotkey 8 EndIf EndFunc ; ==> _8_Tab_Prec Davidowicza 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now