API Guide

The example "Keyboard Animation" isn't working on win Xp.
To test it use the api guide search "Keyboard Animation" example.
It is in the function "GetKeyboardState"
Wat am I doing wrong, Do I have got to change some code to let it work in Win Xp??
THX
[278 byte] By [Bert Willekens] at [2007-11-17 16:55:29]
# 1 Re: API Guide
From msdn:
Remarks
Because the SetKeyboardState function alters the input state of the calling thread and not the global input state of the system, an application cannot use SetKeyboardState to set the NUM LOCK, CAPS LOCK, or SCROLL LOCK (or the Japanese KANA) indicator lights on the keyboard. These can be set or cleared using SendInput to simulate keystrokes.

'so, they are saying it cannot work, but:

Windows NT/2000/XP: The keybd_event function can also toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.
'what do they mean? are they sayibng the contrary as above?

Windows 95/98/Me: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys. It cannot toggle the NUM LOCK key.

In any case: I tryed on win2000, and there was no way using Api guide example...
Cimperiali at 2007-11-10 0:23:14 >
# 2 Re: API Guide
Use either keybd_event function or SendInput Function to accomplish the same on XP and 2000. You can use GetVersionEx function to determine with OS is running and thus which functions to call.
DSJ at 2007-11-10 0:24:21 >
# 3 Re: API Guide
DSJ,

is there a list of all the "vk_?" functions?
like:vk_capslock

THX
Bert Willekens at 2007-11-10 0:25:20 >
# 4 Re: API Guide
Here are Caps, Numlock and scroll... got them from the APIView from AllAPI.net:

Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
DSJ at 2007-11-10 0:26:23 >
# 5 Re: API Guide
DSJ,
can you give me a complete code that does this.
When I press a button the tree lights (Num lock, Caps lock, Scroll lock) goes on.
I can't fiw the code myself
and, I think that DSJ is the best user of the dev-archive forum: he always reply and the code works always.

THX:)
Bert
Bert Willekens at 2007-11-10 0:27:22 >
# 6 Re: API Guide
I grabbed these from Windows.h, I THINK for the alphabet you can use their ASCII values.

/* Virtual key codes */
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#define VK_CANCEL 0x03
#define VK_MBUTTON 0x04
#define VK_BACK 0x08
#define VK_TAB 0x09
#define VK_CLEAR 0x0C
#define VK_RETURN 0x0D
#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_MENU 0x12
#define VK_PAUSE 0x13
#define VK_CAPITAL 0x14
#define VK_ESCAPE 0x1B
#define VK_SPACE 0x20
#define VK_PRIOR 0x21
#define VK_NEXT 0x22
#define VK_END 0x23
#define VK_HOME 0x24
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
#define VK_SELECT 0x29
#define VK_PRINT 0x2A
#define VK_EXECUTE 0x2B
#define VK_SNAPSHOT 0x2C
#define VK_INSERT 0x2D
#define VK_DELETE 0x2E
#define VK_HELP 0x2F
#define VK_NUMPAD0 0x60
#define VK_NUMPAD1 0x61
#define VK_NUMPAD2 0x62
#define VK_NUMPAD3 0x63
#define VK_NUMPAD4 0x64
#define VK_NUMPAD5 0x65
#define VK_NUMPAD6 0x66
#define VK_NUMPAD7 0x67
#define VK_NUMPAD8 0x68
#define VK_NUMPAD9 0x69
#define VK_MULTIPLY 0x6A
#define VK_ADD 0x6B
#define VK_SEPARATOR 0x6C
#define VK_SUBTRACT 0x6D
#define VK_DECIMAL 0x6E
#define VK_DIVIDE 0x6F
#define VK_F1 0x70
#define VK_F2 0x71
#define VK_F3 0x72
#define VK_F4 0x73
#define VK_F5 0x74
#define VK_F6 0x75
#define VK_F7 0x76
#define VK_F8 0x77
#define VK_F9 0x78
#define VK_F10 0x79
#define VK_F11 0x7A
#define VK_F12 0x7B
#define VK_F13 0x7C
#define VK_F14 0x7D
#define VK_F15 0x7E
#define VK_F16 0x7F
#define VK_F17 0x80
#define VK_F18 0x81
#define VK_F19 0x82
#define VK_F20 0x83
#define VK_F21 0x84
#define VK_F22 0x85
#define VK_F23 0x86
#define VK_F24 0x87
#define VK_NUMLOCK 0x90
#define VK_SCROLL 0x91
DSJ at 2007-11-10 0:28:15 >
# 7 Re: API Guide
How do I got to use this list in vb code. Can you give me an example??

THX
Bert Willekens at 2007-11-10 0:29:17 >
# 8 Re: API Guide
Replace #define with Const and 0X with = &H, so that #define VK_LBUTTON 0x01 becomes Const VK_LBUTTON = &H01 and so on.
DSJ at 2007-11-10 0:30:20 >
# 9 Re: API Guide
Sorry but I don't get it. Do I have got to use the keyb_event code:

Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'Clear the form
Me.Cls
keybd_event VK_H, 0, 0, 0 ' press H
keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H
keybd_event VK_E, 0, 0, 0 ' press E
keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0 ' release E
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_O, 0, 0, 0 ' press O
keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0 ' release O
End Sub

and then add the "Const VK_NUMPAD9 = &H69" so I get:

Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'Clear the form
Me.Cls
keybd_event VK_H, 0, 0, 0 ' press H
keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H
keybd_event VK_E, 0, 0, 0 ' press E
keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0 ' release E
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_O, 0, 0, 0 ' press O
keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0 ' release O
Const VK_NUMPAD9 = &H69
End Sub

:confused: :confused: :confused: I am confused
PLEASE HELP ME
Bert Willekens at 2007-11-10 0:31:25 >
# 10 Re: API Guide
Sorry, I found it
But how can i check if the light ( Num, Caps, Scroll) is on/off
Bert Willekens at 2007-11-10 0:32:22 >
# 11 Re: API Guide
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_CAPITAL = &H14

Private Sub Command1_Click()
Dim lRet As Integer
lRet = GetKeyState(VK_CAPITAL)
MsgBox IIf(lRet = 1, "Caps Lock is On", "Caps Lock is off")
End Sub
DSJ at 2007-11-10 0:33:20 >