• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

SendKeys command doesn't work after Microsoft Update

Hi

I have written a VB6 program a while ago and it was working perfectly for years.Today I did a windows update and the program stopped working.What actually happens is that I have a routine which starts another program (Through SHELL) sets the focus on it and with SendKeys I emulated keystroke F2 which actually starts the called program.Easy enough.Obviously the update had some security stuff in it (I have no ideea which update as it took 107 updates from MS today) which kills the sendkeys.Is there any other easy way except api's to simulate a keystroke (my case "F2" key) ?
Here's the routine in question:
As I said this worked perfectly untill a few hours ago.any help would be highly appreciated.


Private Sub Response_B1()
 
Dim pHandle As Long
Dim ITask As Long
Form1.TxtSayit.Text = "Now Starting 3G internet connection  "
currCall.ISpeak.Speak TxtSayit.Text
ITask = Shell("C:\Program Files\3 Mobile\3 Mobile Broadband\3 Mobile Broadband.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, 0, ITask)
If (pHandle <> 0) Then
WaitForSingleObject pHandle, 30000
CloseHandle pHandle
End If
 
 SendKeys "{F2}"
Form1.TxtSayit.Text = "3g connection has been started to retrieve the IP address press 8 "
currCall.ISpeak.Speak TxtSayit.Text
'Form1.Text6.Text = LocalIPAddresses("+")
End Sub

Open in new window

0
Latzi_Marian
Asked:
Latzi_Marian
  • 2
1 Solution
 
FER_GCommented:
Latzi_Marian;
the way to do a sendKey, Without having any problem is using the "keybd_event" API. It's documented that VB Sendkeys have problems in several environs, so it's recomended replace it with "keybd_event" API

FerG
--
Saludos.
Ing. Fernando D. Giletta
San Fco. Cba. Arg.

'IN A MODULE...
Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) 
 
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2
 
public Const VK_0 As Long = &H30
public Const VK_1 As Long = &H31
public Const VK_2 As Long = &H32
public Const VK_3 As Long = &H33
public Const VK_4 As Long = &H34
public Const VK_5 As Long = &H35
public Const VK_6 As Long = &H36
public Const VK_7 As Long = &H37
public Const VK_8 As Long = &H38
public Const VK_9 As Long = &H39
public Const VK_A As Long = &H41
public Const VK_B As Long = &H42
public Const VK_C As Long = &H43
public Const VK_D As Long = &H44
public Const VK_E As Long = &H45
public Const VK_F As Long = &H46
public Const VK_G As Long = &H47
public Const VK_H As Long = &H48
public Const VK_I As Long = &H49
public Const VK_J As Long = &H4A
public Const VK_K As Long = &H4B
public Const VK_L As Long = &H4C
public Const VK_M As Long = &H4D
public Const VK_N As Long = &H4E
public Const VK_O As Long = &H4F
public Const VK_P As Long = &H50
public Const VK_Q As Long = &H51
public Const VK_R As Long = &H52
public Const VK_S As Long = &H53
public Const VK_T As Long = &H54
public Const VK_U As Long = &H55
public Const VK_V As Long = &H56
public Const VK_W As Long = &H57
public Const VK_X As Long = &H58
public Const VK_Y As Long = &H59
public Const VK_Z As Long = &H5A
public Const VK_ADD As Long = &H6B
public Const VK_ATTN As Long = &HF6
public Const VK_BACK As Long = &H8
public Const VK_CANCEL As Long = &H3
public Const VK_CAPITAL As Long = &H14
public Const VK_CLEAR As Long = &HC
public Const VK_CONTROL As Long = &H11
public Const VK_CRSEL As Long = &HF7
public Const VK_DECIMAL As Long = &H6E
public Const VK_DELETE As Long = &H2E
public Const VK_DIVIDE As Long = &H6F
public Const VK_DOWN As Long = &H28
public Const VK_END As Long = &H23
public Const VK_EREOF As Long = &HF9
public Const VK_ESCAPE As Long = &H1B
public Const VK_EXECUTE As Long = &H2B
public Const VK_EXSEL As Long = &HF8
public Const VK_F1 As Long = &H70
public Const VK_F10 As Long = &H79
public Const VK_F11 As Long = &H7A
public Const VK_F12 As Long = &H7B
public Const VK_F13 As Long = &H7C
public Const VK_F14 As Long = &H7D
public Const VK_F15 As Long = &H7E
public Const VK_F16 As Long = &H7F
public Const VK_F17 As Long = &H80
public Const VK_F18 As Long = &H81
public Const VK_F19 As Long = &H82
public Const VK_F2 As Long = &H71
public Const VK_F20 As Long = &H83
public Const VK_F21 As Long = &H84
public Const VK_F22 As Long = &H85
public Const VK_F23 As Long = &H86
public Const VK_F24 As Long = &H87
public Const VK_F3 As Long = &H72
public Const VK_F4 As Long = &H73
public Const VK_F5 As Long = &H74
public Const VK_F6 As Long = &H75
public Const VK_F7 As Long = &H76
public Const VK_F8 As Long = &H77
public Const VK_F9 As Long = &H78
public Const VK_HELP As Long = &H2F
public Const VK_HOME As Long = &H24
public Const VK_INSERT As Long = &H2D
public Const VK_LBUTTON As Long = &H1
public Const VK_LCONTROL As Long = &HA2
public Const VK_LEFT As Long = &H25
public Const VK_LMENU As Long = &HA4
public Const VK_LSHIFT As Long = &HA0
public Const VK_MBUTTON As Long = &H4
public Const VK_MENU As Long = &H12
public Const VK_MULTIPLY As Long = &H6A
public Const VK_NEXT As Long = &H22
public Const VK_NONAME As Long = &HFC
public Const VK_NUMLOCK As Long = &H90
public Const VK_NUMPAD0 As Long = &H60
public Const VK_NUMPAD1 As Long = &H61
public Const VK_NUMPAD2 As Long = &H62
public Const VK_NUMPAD3 As Long = &H63
public Const VK_NUMPAD4 As Long = &H64
public Const VK_NUMPAD5 As Long = &H65
public Const VK_NUMPAD6 As Long = &H66
public Const VK_NUMPAD7 As Long = &H67
public Const VK_NUMPAD8 As Long = &H68
public Const VK_NUMPAD9 As Long = &H69
public Const VK_OEM_CLEAR As Long = &HFE
public Const VK_PA1 As Long = &HFD
public Const VK_PAUSE As Long = &H13
public Const VK_PLAY As Long = &HFA
public Const VK_PRINT As Long = &H2A
public Const VK_PRIOR As Long = &H21
public Const VK_PROCESSKEY As Long = &HE5
public Const VK_RBUTTON As Long = &H2
public Const VK_RCONTROL As Long = &HA3
public Const VK_RETURN As Long = &HD
public Const VK_RIGHT As Long = &H27
public Const VK_RMENU As Long = &HA5
public Const VK_RSHIFT As Long = &HA1
public Const VK_SCROLL As Long = &H91
public Const VK_SELECT As Long = &H29
public Const VK_SEPARATOR As Long = &H6C
public Const VK_SHIFT As Long = &H10
public Const VK_SNAPSHOT As Long = &H2C
public Const VK_SPACE As Long = &H20
public Const VK_SUBTRACT As Long = &H6D
public Const VK_TAB As Long = &H9
public Const VK_UP As Long = &H26
public Const VK_ZOOM As Long = &HFB 
 
Public Sub SendKeyAlter(cKey As Long)
    keybd_event cKey, 0, 0, 0
    keybd_event cKey, 0, KEYEVENTF_KEYUP, 0
End Sub
 
 
'AT THE FORM.
'....
'SendKeys "{F2}" REPLACE THIS LINE BY...
SendKeyAlter VK_F2

Open in new window

0
 
Latzi_MarianSystems IntegratorAuthor Commented:
It's working perfectly.Gracias.
0
 
FER_GCommented:
You're welcome. De nada!!!

Saludos.
FerG
--
Ing. Fernando D. Giletta
San Fco. Cba. Arg.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now