Declaration of KeyboardProc?
Can't find it in API Viewer???
What is the declaration?
Declare Function KeyboardProc Alias??
Printable View
Declaration of KeyboardProc?
Can't find it in API Viewer???
What is the declaration?
Declare Function KeyboardProc Alias??
Try this
VB Code:
Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Don't worry about that.
What is a callback thingo majig?
Megatron, Matthew, Aaron, Serge?
You use a callback to recive an "event" from another process ie. the system.Quote:
What is a callback thingo majig?
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:confused:
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?
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.
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.
What's the difference between WindowProc and SetWindowsHookEx?
Can WindowProc be system wide?
How do I check the bits?Quote:
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.
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...
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
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.....
How do I check the lParam for the (above mentioned - by u) bits?
You can get this by looking on the first 16 bits of the lParam.Quote:
e --> returned: eeeeeeeeeeeeeeeeee
If I remember correctly this should give you the first 16 bits:
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.VB Code:
intResult = lParam And &HFFFF&
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
How can i check the bits?
Like what is the conversion scale?
like 32 bits = &HHHHHHHHH& or what?
How do i know/find out?
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
How do I get the 30th bit?Quote:
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.
pUBLIC const bit30 = 2^30?
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?
Still need help with this one :rolleyes:
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
what is the kf_keyup const?
There arn't any.:eek:Quote:
what is the kf_keyup const?
OK, I'll be nice.Quote:
what is the kf_keyup const?
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
I give up...
Oh well it wasn't a bad start into all that Subclass and Hooking mumbo jumbo...