Author Topic: keybd_event PHUN !  (Read 451 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
keybd_event PHUN !
« on: June 07, 2020, 01:32:10 PM »
 :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:   
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

felipe

  • Member
  • *****
  • Posts: 1336
  • Eagles are just great!
Re: keybd_event PHUN !
« Reply #1 on: June 08, 2020, 02:10:53 AM »
 :thumbsup: Nice you have succeeded.
Felipe.

Vortex

  • Member
  • *****
  • Posts: 2383
Re: keybd_event PHUN !
« Reply #2 on: June 09, 2020, 05:16:03 AM »
Hi Hutch,

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

Code: [Select]
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--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: keybd_event PHUN !
« Reply #3 on: June 13, 2020, 02:50:34 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2383
Re: keybd_event PHUN !
« Reply #4 on: June 14, 2020, 10:55:57 PM »
Hi Hutch,

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

K_F

  • Member
  • *****
  • Posts: 1617
  • Anybody out there?
Re: keybd_event PHUN !
« Reply #5 on: June 15, 2020, 07:29:49 PM »
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....'