|
-
Nov 4th, 2001, 06:31 AM
#1
Thread Starter
Conquistador
Declaration
Declaration of KeyboardProc?
Can't find it in API Viewer???
What is the declaration?
Declare Function KeyboardProc Alias??
-
Nov 4th, 2001, 06:33 AM
#2
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 4th, 2001, 06:36 AM
#3
Try this
VB Code:
Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
-
Nov 4th, 2001, 06:40 AM
#4
Thread Starter
Conquistador
Don't worry about that.
What is a callback thingo majig?
Megatron, Matthew, Aaron, Serge?
-
Nov 4th, 2001, 06:53 AM
#5
What is a callback thingo majig?
You use a callback to recive an "event" from another process ie. the system.
When settting up the callback, you pass the other process a memory address (using AddressOf) in memory. A so called pointer function.
The other process can then call this memory address and thereby cause your code to execute.
In order for this to work, the callback return function must forfill surden requirements, like arguments or the it will cause a memory error, and thereafter a program crash.
I'm not is this was what you asked for
-
Nov 4th, 2001, 07:08 AM
#6
Thread Starter
Conquistador
Yeah thanks man, I worked that out...
What about this code:
VB Code:
Function KeyboardProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print code & ":" & wParam & ":" & lParam
If Asc(LCase(Chr(wParam))) >= Asc("a") And Asc(LCase(Chr(wParam))) <= Asc("z") And wParam <> prevKey Or wParam = 32 Then
Form1.Text1.Text = Form1.Text1.Text & Chr(wParam)
prevKey = wParam
End If
End Function
I don't want the characters to be entered many times, so how can i filter it?
using lparam?
-
Nov 4th, 2001, 07:15 AM
#7
lParam should give the information you wan't.
This is the structure of lParamn (the use of the bits)
0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25–28 Reserved.
29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
This information will properly also be handy:
Repeat Count
You can check the repeat count to determine whether a keystroke message represents more than one keystroke. The system increments the count when the keyboard generates WM_KEYDOWN or WM_SYSKEYDOWN messages faster than an application can process them. This often occurs when the user holds down a key long enough to start the keyboard's automatic repeat feature. Instead of filling the system message queue with the resulting key-down messages, the system combines the messages into a single key down message and increments the repeat count. Releasing a key cannot start the automatic repeat feature, so the repeat count for WM_KEYUP and WM_SYSKEYUP messages is always set to 1.
Hope this helps you.
-
Nov 4th, 2001, 07:16 AM
#8
Ups, forgot this part.
Previous Key-State Flag
The previous key-state flag indicates whether the key that generated the keystroke message was previously up or down. It is 1 if the key was previously down and 0 if the key was previously up. You can use this flag to identify keystroke messages generated by the keyboard's automatic repeat feature. This flag is set to 1 for WM_KEYDOWN and WM_SYSKEYDOWN keystroke messages generated by the automatic repeat feature. It is always set to 0 for WM_KEYUP and WM_SYSKEYUP messages.
-
Nov 4th, 2001, 07:18 AM
#9
Thread Starter
Conquistador
What's the difference between WindowProc and SetWindowsHookEx?
Can WindowProc be system wide?
-
Nov 4th, 2001, 07:26 AM
#10
Thread Starter
Conquistador
Originally posted by AIS_DK
lParam should give the information you wan't.
This is the structure of lParamn (the use of the bits)
0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25–28 Reserved.
29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
This information will properly also be handy:
Repeat Count
You can check the repeat count to determine whether a keystroke message represents more than one keystroke. The system increments the count when the keyboard generates WM_KEYDOWN or WM_SYSKEYDOWN messages faster than an application can process them. This often occurs when the user holds down a key long enough to start the keyboard's automatic repeat feature. Instead of filling the system message queue with the resulting key-down messages, the system combines the messages into a single key down message and increments the repeat count. Releasing a key cannot start the automatic repeat feature, so the repeat count for WM_KEYUP and WM_SYSKEYUP messages is always set to 1.
Hope this helps you.
How do I check the bits?
I just want to check if it is the same key code being sent i.e. held down
So how do i find those messages from the lParam?
i want to intercept a message from my keyboard, (it has fancy buttons) and get my program to process them.
You have been a great help so far anyway...
-
Nov 4th, 2001, 07:26 AM
#11
WindowProc recieves messages sent to a window, and only to that window. It's in VB only allowed to intercept messages sent to a window within the same process, and can therefore not be system wide.
A hook on the other hand, intersepts messages before the system handles it (almost), and you the through this take control of the entire system (in teory).
Thorugh WIndowProc you only get messages like WM_KEYDOWN once, for each key press, even if the user holds down the key. With a hook, you can intercept all the messages sent from the Keyboard to windows, witch also means that you will get alot more messages, and therefore this can result in a slowdown in your system
-
Nov 4th, 2001, 07:33 AM
#12
Thread Starter
Conquistador
Is there anyway to get them at the same rate?
i.e.
I type in likkkkkkkkkkkkkkkkkkeeeeeeeeeeeeee this (holding down)
and i can get all of the k's and e's, instead of pressing e
i.e.
e --> returned: eeeeeeeeeeeeeeeeee
I will need to use a Hook then, because i think the keyboard buttons are not sent to the active window.....
-
Nov 4th, 2001, 07:42 AM
#13
Thread Starter
Conquistador
How do I check the lParam for the (above mentioned - by u) bits?
-
Nov 4th, 2001, 07:47 AM
#14
e --> returned: eeeeeeeeeeeeeeeeee
You can get this by looking on the first 16 bits of the lParam.
If I remember correctly this should give you the first 16 bits:
VB Code:
intResult = lParam And &HFFFF&
When it comes to key-codes, which is what you wan't to look at, if you wan't to know which key has been pressed, you can either test the function, by pressing the button and debuging the value, and you should have it, or have a look on the attached word document.
If you wan't to check a surden key is pressed, you also need to test the transition state, the value of the can be trieved by using the constant:
VB Code:
Public Const KF_TRANSITION_UP As Long = &H80000000
'like this
If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
'User is releasing the key (key going UP)
End If
-
Nov 4th, 2001, 07:58 AM
#15
Thread Starter
Conquistador
How can i check the bits?
Like what is the conversion scale?
like 32 bits = &HHHHHHHHH& or what?
How do i know/find out?
-
Nov 4th, 2001, 08:34 AM
#16
If you wan't to know the state of a single bit, you must use the example I gave you
VB Code:
Public Const KF_TRANSITION_UP As Long = &H80000000
If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
'User is releasing the key (key going UP)
End If
If you don't know the value of a const, you can caculate it. It goes like this:
Bit 1 -> const = 1
Bit 2 -> const = 2
Bit 3 -> const = 4
Bit 4 -> const = 8
Bit 5 -> const = 16
Bit 6 -> const = 32
and so on...
Bit x -> const = 2 power x (2^x).
If you wan't get the repeat count, this should do it:
VB Code:
Count = LowWord(lParam)
Function LoWord(ByVal Num As Long) As Integer
If Num And &H8000& Then
LoWord = Num Or &HFFFF0000
Else
LoWord = Num And &HFFFF&
End If
End Function
-
Nov 4th, 2001, 07:52 PM
#17
Thread Starter
Conquistador
Value Description
0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25–28 Reserved.
29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
How do I get the 30th bit?
pUBLIC const bit30 = 2^30?
-
Nov 4th, 2001, 08:15 PM
#18
Thread Starter
Conquistador
i tried Public Const KF_KEYUP As Long = &H40000000
But it's not working as desired?
Can you tell me just how to get the key up messages?
How would i get exactly what is being typed on the computer?
-
Nov 5th, 2001, 02:28 AM
#19
Thread Starter
Conquistador
^BUMP^
Still need help with this one
-
Nov 5th, 2001, 02:43 AM
#20
I did like this, in my program (program for creating customized menues)
I used it to emulate accelerator key-codes. Like CTRL + S in VB. The way is works, it that i listens for key-presses, but remembers the state of the Control button, as long as CTRL is pressed, it should accelerate the menuitems.
AccelerateMenuItem is just a sub I call in my program.
VB Code:
Public Const HC_ACTION As Long = 0
Public Const KF_DOWN As Long = &H40000000
Public Const KF_TRANSITION_UP As Long = &H80000000
'Keyboard hook sub
Static blnControl As Boolean
If ncode = HC_ACTION Then
If blnControl Then
Select Case wParam
Case Is = VK_CONTROL
If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then blnControl = False
Case Is = VK_A: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlA
Case Is = VK_B: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlB
Case Is = VK_C: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlC
Case Is = VK_D: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlD
Case Is = VK_E: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlE
Case Is = VK_F: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF
Case Is = VK_G: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlG
Case Is = VK_H: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlH
Case Is = VK_I: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlI
Case Is = VK_J: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlJ
Case Is = VK_K: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlK
Case Is = VK_L: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlL
Case Is = VK_M: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlM
Case Is = VK_N: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlN
Case Is = VK_O: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlO
Case Is = VK_P: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlP
Case Is = VK_Q: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlQ
Case Is = VK_R: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlR
Case Is = VK_S: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlS
Case Is = VK_T: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlT
Case Is = VK_U: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlU
Case Is = VK_V: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlV
Case Is = VK_W: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlW
Case Is = VK_X: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlX
Case Is = VK_Y: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlY
Case Is = VK_Z: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlZ
Case Is = VK_F1: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF1
Case Is = VK_F2: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF2
Case Is = VK_F3: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF3
Case Is = VK_F4: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF4
Case Is = VK_F5: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF5
Case Is = VK_F6: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF6
Case Is = VK_F7: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF7
Case Is = VK_F8: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF8
Case Is = VK_F9: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF9
Case Is = VK_F10: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF10
Case Is = VK_F11: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF11
Case Is = VK_F12: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF12
End Select
Else
Select Case wParam
Case Is = VK_CONTROL
If (lParam And KF_DOWN) = 0 Then
blnControl = True
ElseIf (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
blnControl = False
End If
Case Is = VK_F1: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F1
Case Is = VK_F2: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F2
Case Is = VK_F3: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F3
Case Is = VK_F4: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F4
Case Is = VK_F5: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F5
Case Is = VK_F6: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F6
Case Is = VK_F7: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F7
Case Is = VK_F8: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F8
Case Is = VK_F9: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F9
Case Is = VK_F10: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F10
Case Is = VK_F11: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F11
Case Is = VK_F12: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F12
End Select
End If
End If
'End of sub
-
Nov 5th, 2001, 03:20 AM
#21
Thread Starter
Conquistador
what is the kf_keyup const?
-
Nov 5th, 2001, 03:28 AM
#22
what is the kf_keyup const?
There arn't any.
-
Nov 5th, 2001, 03:36 AM
#23
what is the kf_keyup const?
OK, I'll be nice.
You can test if a button goes us, by testing it's transition state. If it's true, then the button's state was previously down.
So this actually tests if the buttons comes from it's down state:
VB Code:
(lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP
-
Nov 5th, 2001, 08:32 AM
#24
Thread Starter
Conquistador
I give up...
Oh well it wasn't a bad start into all that Subclass and Hooking mumbo jumbo...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|