News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

keybd_event PHUN !

Started by hutch--, June 07, 2020, 01:32:10 PM

Previous topic - Next topic

hutch--

 :biggrin:

For those with a sense of humour, this wasted some hours trying to figure out why "keybd_event" did not work.

Ala Microsoft,
Quote
An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the Windows clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.
Ready to scrap the idea, I tried the other constant "KEYEVENTF_EXTENDEDKEY" and BINGO it works like a charm.

            rcall ShowWindow,hWin,SW_HIDE
            rcall SleepEx,250,0
            rcall keybd_event,VK_SNAPSHOT,0,KEYEVENTF_EXTENDEDKEY,0
            rcall SleepEx,250,0
            rcall ShowWindow,hWin,SW_SHOW

Ah Microsoft, you've dunnit again.  :skrewy:   

felipe

 :thumbsup: Nice you have succeeded.

Vortex

Hi Hutch,

Thanks for the code :thumbsup: It works well with my clipboard tool :

main PROC uses esi

LOCAL hBmp      :DWORD
LOCAL pBitmap   :DWORD
LOCAL hGlobal   :DWORD
LOCAL pcbSize   :DWORD
LOCAL pStream   :DWORD
LOCAL pd        :PICTDESC

    lea         esi,buffer
    invoke      ParseCmdLine,esi
    cmp         eax,2
    je          @f

    invoke      StdOut,ADDR message
    ret
@@:
    invoke      keybd_event,VK_SNAPSHOT,0,KEYEVENTF_EXTENDEDKEY,0
    invoke      SleepEx,250,0
    invoke      GetDesktopWindow
    invoke      OpenClipboard,eax
    invoke      GetClipboardData,CF_BITMAP
    mov         hBmp,eax
    invoke      CloseClipboard
.
.

hutch--

Hi Erol,

I have been tracking down a problem with an old app that if it crashes, it makes a mess of the clipboard and the closest I can come to fixing it is to close then clear the clipboard. The current test code,

            rcall CloseClipboard                        ; close and clear the clipboard
            rcall EmptyClipboard
            rcall keybd_event,VK_SNAPSHOT,0, \
                  KEYEVENTF_EXTENDEDKEY,0               ; capture screen to clipboard
            rcall SendMessage,HWND_BROADCAST, \
                  WM_CHAR,VK_SNAPSHOT,0                 ; backup technique

Funny enough the "SendMessage" version also works OK but as it is placed in the message queue, its too slow. I included it to ensure the keyup was done correctly.

Vortex

Hi Hutch,

Thanks for the update. I will update my Poasm example.

K_F

Next trick, is to put it into mpeg4 format with sound ;)
I might look at that if I have time  :thumbsup:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'