Results 1 to 24 of 24

Thread: Declaration

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Declaration

    Declaration of KeyboardProc?

    Can't find it in API Viewer???

    What is the declaration?

    Declare Function KeyboardProc Alias??

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    AIS_DK
    Guest
    Try this

    VB Code:
    1. Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

  4. #4

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Don't worry about that.
    What is a callback thingo majig?

    Megatron, Matthew, Aaron, Serge?

  5. #5
    AIS_DK
    Guest
    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

  6. #6

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yeah thanks man, I worked that out...

    What about this code:

    VB Code:
    1. Function KeyboardProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Debug.Print code & ":" & wParam & ":" & lParam
    3. If Asc(LCase(Chr(wParam))) >= Asc("a") And Asc(LCase(Chr(wParam))) <= Asc("z") And wParam <> prevKey Or wParam = 32 Then
    4.     Form1.Text1.Text = Form1.Text1.Text & Chr(wParam)
    5.     prevKey = wParam
    6. End If
    7. End Function

    I don't want the characters to be entered many times, so how can i filter it?

    using lparam?

  7. #7
    AIS_DK
    Guest
    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.

  8. #8
    AIS_DK
    Guest
    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.

  9. #9

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    What's the difference between WindowProc and SetWindowsHookEx?

    Can WindowProc be system wide?

  10. #10

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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...

  11. #11
    AIS_DK
    Guest
    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

  12. #12

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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.....

  13. #13

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    How do I check the lParam for the (above mentioned - by u) bits?

  14. #14
    AIS_DK
    Guest
    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:
    1. 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:
    1. Public Const KF_TRANSITION_UP As Long = &H80000000
    2.  
    3. 'like this
    4.  
    5. If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
    6.    'User is releasing the key (key going UP)
    7. End If

  15. #15

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    How can i check the bits?

    Like what is the conversion scale?

    like 32 bits = &HHHHHHHHH& or what?

    How do i know/find out?

  16. #16
    AIS_DK
    Guest
    If you wan't to know the state of a single bit, you must use the example I gave you
    VB Code:
    1. Public Const KF_TRANSITION_UP As Long = &H80000000
    2.  
    3. If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
    4.    'User is releasing the key (key going UP)
    5. 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:
    1. Count = LowWord(lParam)
    2.  
    3. Function LoWord(ByVal Num As Long) As Integer
    4.     If Num And &H8000& Then
    5.         LoWord = Num Or &HFFFF0000
    6.     Else
    7.         LoWord = Num And &HFFFF&
    8.     End If
    9. End Function

  17. #17

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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?

  18. #18

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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?

  19. #19

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    ^BUMP^

    Still need help with this one

  20. #20
    AIS_DK
    Guest
    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:
    1. Public Const HC_ACTION As Long = 0
    2. Public Const KF_DOWN As Long = &H40000000
    3. Public Const KF_TRANSITION_UP As Long = &H80000000
    4.  
    5. 'Keyboard hook sub
    6. Static blnControl As Boolean
    7.  
    8. If ncode = HC_ACTION Then
    9.     If blnControl Then
    10.         Select Case wParam
    11.         Case Is = VK_CONTROL
    12.             If (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then blnControl = False
    13.         Case Is = VK_A: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlA
    14.         Case Is = VK_B: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlB
    15.         Case Is = VK_C: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlC
    16.         Case Is = VK_D: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlD
    17.         Case Is = VK_E: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlE
    18.         Case Is = VK_F: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF
    19.         Case Is = VK_G: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlG
    20.         Case Is = VK_H: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlH
    21.         Case Is = VK_I: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlI
    22.         Case Is = VK_J: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlJ
    23.         Case Is = VK_K: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlK
    24.         Case Is = VK_L: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlL
    25.         Case Is = VK_M: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlM
    26.         Case Is = VK_N: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlN
    27.         Case Is = VK_O: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlO
    28.         Case Is = VK_P: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlP
    29.         Case Is = VK_Q: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlQ
    30.         Case Is = VK_R: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlR
    31.         Case Is = VK_S: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlS
    32.         Case Is = VK_T: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlT
    33.         Case Is = VK_U: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlU
    34.         Case Is = VK_V: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlV
    35.         Case Is = VK_W: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlW
    36.         Case Is = VK_X: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlX
    37.         Case Is = VK_Y: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlY
    38.         Case Is = VK_Z: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlZ
    39.         Case Is = VK_F1: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF1
    40.         Case Is = VK_F2: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF2
    41.         Case Is = VK_F3: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF3
    42.         Case Is = VK_F4: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF4
    43.         Case Is = VK_F5: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF5
    44.         Case Is = VK_F6: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF6
    45.         Case Is = VK_F7: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF7
    46.         Case Is = VK_F8: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF8
    47.         Case Is = VK_F9: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF9
    48.         Case Is = VK_F10: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF10
    49.         Case Is = VK_F11: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF11
    50.         Case Is = VK_F12: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem CtrlF12
    51.         End Select
    52.     Else
    53.         Select Case wParam
    54.         Case Is = VK_CONTROL
    55.             If (lParam And KF_DOWN) = 0 Then
    56.                 blnControl = True
    57.             ElseIf (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP Then
    58.                 blnControl = False
    59.             End If
    60.         Case Is = VK_F1: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F1
    61.         Case Is = VK_F2: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F2
    62.         Case Is = VK_F3: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F3
    63.         Case Is = VK_F4: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F4
    64.         Case Is = VK_F5: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F5
    65.         Case Is = VK_F6: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F6
    66.         Case Is = VK_F7: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F7
    67.         Case Is = VK_F8: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F8
    68.         Case Is = VK_F9: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F9
    69.         Case Is = VK_F10: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F10
    70.         Case Is = VK_F11: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F11
    71.         Case Is = VK_F12: If (lParam And KF_DOWN) = 0 Then AccelerateMenuItem F12
    72.         End Select
    73.     End If
    74. End If
    75. 'End of sub

  21. #21

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    what is the kf_keyup const?

  22. #22
    AIS_DK
    Guest
    what is the kf_keyup const?
    There arn't any.

  23. #23
    AIS_DK
    Guest
    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:
    1. (lParam And KF_TRANSITION_UP) = KF_TRANSITION_UP

  24. #24

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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
  •  



Click Here to Expand Forum to Full Width