PDA

View Full Version : Bloc Maiusc E Win 2000


CIUFFO
04-12-2002, 00:04
Perchè questa sub di access in windows 2000 non funziona correttamente? praticamente non accende il led sulla tastiera.

Sotto windows 98 tutto ok, all'apertura del form imposta automaticamente il tasto caps lock come inserito e il led relativo acceso.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

Sub SetCapsLock(ByVal bnewValue As Boolean)
' get current state of all 256 virtual keys
Dim keystat(0 To 255) As Byte
GetKeyboardState keystat(0)
' modify bit 0 of the relevant item, and store back
keystat(vbKeyCapital) = (keystat(vbKeyCapital) And &HFE) Or (bnewValue And 1)
SetKeyboardState keystat(0)
End Sub

Private Sub Form_Open(Cancel As Integer)
SetCapsLock True
End Sub

CIUFFO
09-12-2002, 20:19
grazie mille!!

P.S. perchè hai cancellato la risposta?

cionci
09-12-2002, 20:49
Non l'ho cancellata... Il forum ha avuto problemi... Leggi l'annuncio in rilievo in tutte le sezioni...

Postala che potrebbe servire a qualcuno... Io non l'ho salvata...

Comunque sei capitato proprio a puntino...stavo facendo esperimenti proprio con keybd_event...

CIUFFO
10-12-2002, 19:28
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 Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

Sub SetCapsLock(ByVal bnewValue As Boolean)
' get current state of all 256 virtual keys
Dim keystat(0 To 255) As Byte
GetKeyboardState keystat(0)
' modify bit 0 of the relevant item, and store back
If keystat(vbKeyCapital) <> ((keystat(vbKeyCapital) And &HFE) Or (bnewValue And 1)) Then
keybd_event 20, vbKeyCapital, KEYEVENTF_EXTENDEDKEY, 0
keybd_event 20, vbKeyCapital, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End If
End Sub

CIUFFO
10-12-2002, 19:32
Perchè il mio codice funziona in win 98 e non in win 2000
potresti illustrarmi la tua modifica?

cionci
10-12-2002, 19:35
Secondo MSDN :
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.
In teoria non dovrebbe funzionare nemmeno in 98...

keybd_event è una alternativa a SendInput per inviare solamente eventi di tastiera...

La costante 20 che passo come primo parametro è il Virtual Key corrispondente al CAPS LOCK...

CIUFFO
10-12-2002, 19:39
Ti assicuro che funziona benissimo
provalo

cionci
10-12-2002, 19:40
Originariamente inviato da CIUFFO
[B]Ti assicuro che funziona benissimo
provalo
Ci credo che funzioni...per carità...ma in teoria non dovrebbe funzionare...almeno secondo la documentazione...

CIUFFO
10-12-2002, 19:46
come posso avere una lista delle costanti virtual key della tastiera?

cionci
10-12-2002, 20:07
C'è su MSDN alla voce "Virtual Key Codes"...
Se non ce l'hai te lo incollo nel thread...

CIUFFO
11-12-2002, 20:34
Non le ho trovate, potresti essere più preciso?

cionci
13-12-2002, 16:28
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/VirtualKeyCodes.asp

CIUFFO
15-12-2002, 00:47
Sei grande :) Thank you.