IS THERE ANY alternative for SENDKEYS (1 Viewer)

MBMSOFT

Registered User.
Local time
Today, 05:12
Joined
Jan 29, 2010
Messages
90
WHEN I USE SENDKEYS in XP i don't have any specific problems... but on win7 they make a lot of confusion with num lock ...when i use sendkeys in win7 num lock sometimes is going off ...
so I red around that i could replace them with API but i didn't find any clear example...
ANY IDEA TO SOLVE THIS...
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:12
Joined
Jan 20, 2009
Messages
12,852
Exactly how are you using SendKeys?
 

MBMSOFT

Registered User.
Local time
Today, 05:12
Joined
Jan 29, 2010
Messages
90
I think i found a way to replace sendkeys with API....
So I'm steel testing the way... but it seems to work properly....
The code is as follow... Any suggestions to improve the code are welcome ...

Code:
Option Compare Database
Option Explicit
 
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_NUMLOCK = &H90
Private Const VK_F4 = &H73
Private Const VK_F12 = &H7B
Private Const VK_ENTER = &HD
Private Const VK_ESCAPE = &H1B
Private Const VK_TAB = &H9
Private Const VK_SHIFT = &H10
Private Const VK_RIGHT = &H27
Private Const VK_PGUP = &H21

' so it should be created constants for all keys you need to use
' The value key constant table you may found at:
'http://msdn.microsoft.com/en-us/library/ft8xdf67(v=vs.71).aspx

Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

' so you sholud creat functions or subs for the kyes
' and just call them when you need to use

Function F4()
    keybd_event VK_F4, 1, 0, 0
End Function
Function F12()
    keybd_event VK_F12, 1, 0, 0
End Function
Function ENT()
    keybd_event VK_ENTER, 1, 0, 0
End Function
Function ESC()
    keybd_event VK_ESCAPE, 1, 0, 0
End Function
Function eTAB()
    keybd_event VK_TAB, 1, 0, 0
End Function
Function esTAB()
    keybd_event VK_SHIFT, 1, 0, 0
    keybd_event VK_TAB, 1, 0, 0
    keybd_event VK_SHIFT, 1, KEYEVENTF_KEYUP, 0
End Function
Function SHIFT()
    keybd_event VK_SHIFT, 1, 0, 0
    keybd_event VK_SHIFT, 1, KEYEVENTF_KEYUP, 0
End Function
Function eRIGHT()
    keybd_event VK_RIGHT, 1, 0, 0
End Function
Function PGUP()
    keybd_event VK_PGUP, 1, 0, 0
End Function

It is simple and as it looks it works properly and more stable then sendkeys
 

bpotter

New member
Local time
Yesterday, 21:12
Joined
Aug 28, 2018
Messages
2
I tried implementing the sendkeys work around that MBMSoft suggested. However, I can not seem to get it to function. In short, I was using send keys esc and now I want to pass the esc command through the method above. I have placed the above code into a module and am trying to call it from a form's button click. I have had no luck. Any suggestions would be great.

Thank you,
 

Mark_

Longboard on the internet
Local time
Yesterday, 21:12
Joined
Sep 12, 2017
Messages
2,111
What are you trying to send an esc to?
 

Users who are viewing this thread

Top Bottom