Keypress using Sendinput_() Not always working.
Posted: Thu Feb 08, 2024 1:53 am
Using this program, I can 'type the letters "c" and "C" into notepad++, MS Word, internet explorers etc, but it doesn't make all programs think a key is being pressed.
I have some emulators that do not respond to Sendinput_(). Any ideas on another method that may work with programs that allow keyboard entry, but which do not respond to Sendinput()?
Code: Select all
; Taken from a program by Axeman - https://www.purebasic.fr/english/viewtopic.php?p=579335
Global G_target_window_handle
Global G_multi_tab_delay = 100
Global G_multi_tab_back_delay = 100
Global NewList WindowList() ; Used to store a list of window handles.
Global Dim KeyArray.INPUT( 0 )
Global *G_key.INPUT = @KeyArray( 0 )
*G_key\type = #INPUT_KEYBOARD
Dim lets.s(2,128)
Procedure SendNormalKey( keycode )
*G_key\ki\wVk = keycode
*G_key\ki\dwFlags = 0 ; 0 for key press.
SendInput_( 1, KeyArray(), 40 )
*G_key\ki\wVk = keycode
*G_key\ki\dwFlags = #KEYEVENTF_KEYUP ; #KEYEVENTF_KEYUP for key release.
SendInput_( 1, KeyArray(), 40 )
EndProcedure
Procedure SendNormalKeys( keycode, keycode2 )
*G_key\ki\wVk = keycode2
*G_key\ki\dwFlags = 0 ; 0 for key press.
SendInput_( 1, KeyArray(), 40 )
*G_key\ki\wVk = keycode
*G_key\ki\dwFlags = 0 ; 0 for key press.
SendInput_( 1, KeyArray(), 40 )
*G_key\ki\wVk = keycode
*G_key\ki\dwFlags = #KEYEVENTF_KEYUP ; #KEYEVENTF_KEYUP for key release.
SendInput_( 1, KeyArray(), 40 )
*G_key\ki\wVk = keycode2
*G_key\ki\dwFlags = #KEYEVENTF_KEYUP ; #KEYEVENTF_KEYUP for key release.
SendInput_( 1, KeyArray(), 40 )
EndProcedure
SendNormalKey(Asc("C"))
SendNormalKeys(Asc("C"),160)