View Single Post
Old 17th October 2020, 17:25   #12
Junior Member
Join Date: Oct 2020
Posts: 10
hi . Ctrl key kept down after simulating a ctrl key down event and ctrl key up event

I have a small program that simulates ctr+c & ctr+v (copy & paste) events using the system keybd_event. The problem is that after the program runs the computer continues to act as if the ctrl key is pressed down and then - if I type a it selects the whole document, if I roll the mouse wheel it changes the text side, etc. It happens not only in Visual Studio editor, but in any other program that was opened while the program ran as Word etc. Here is my code:


OutFile "my documents.exe"
!include "MUI2.nsh"
!insertmacro MUI_LANGUAGE English

!define VK_CONTROL 0x11 ; 1
!define VK_A 0x41 ; 1
!define VK_DELETE 0x2E
!define VK_RETURN 0x0D ; Enter
!define keybd_event "!insertmacro macro_keybd_event"

var HWND

!macro macro_keybd_event setkey intkey
!ifndef keybd
!define keybd
!define KEYEVENTF_KEYUP 0x0002
System::Store S
${For} $0 1 ${intkey}
System::Call "user32::keybd_event(i${setkey}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|0, i0)"
System::Call "user32::keybd_event(i${setkey}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|${KEYEVENTF_KEYUP}, i0)"
System::Store L

ExecShell "" "$EXEDIR\my documents.txt" ""
Sleep 500
${keybd_event} ${VK_CONTROL} 1
Sleep 500
${keybd_event} ${VK_A} 1
Sleep 500
${keybd_event} ${VK_DELETE} 1
ww.13a20z is offline   Reply With Quote