Results 1 to 15 of 15

Thread: [RESOLVED] Numpad

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Resolved [RESOLVED] Numpad

    Hi,
    Im currently creating a numpad. Have used the sendkeys function, but it doesnt allow me to use multiply, divide, and plus. Enter as well as numlocks not working either. Could someone help me? I have enclosed an attachment with what Im working on right now.

    Thanks heaps
    Attached Files Attached Files

  2. #2

  3. #3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Re: Numpad

    Hi,
    Thanks for the reply so quickly, the divide as well as plus is working fine now. But with multiply when clicked it deletes the stuff in the textbox and shows:

    {*}


    As for:
    textbox is not multiline
    How do i make it multiline?

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Numpad

    Here is your code, modified. I added some code that I found at CodeGuru. BTW you should always use Option Explicit

    VB Code:
    1. Option Explicit
    2. Private Declare Sub keybd_event Lib "user32" _
    3.   (ByVal bVk As Byte, ByVal bScan As Byte, _
    4.   ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    5.  
    6. Private Declare Function MapVirtualKey Lib "user32" _
    7.    Alias "MapVirtualKeyA" _
    8.   (ByVal wCode As Long, ByVal wMapType As Long) As Long
    9.  
    10. Private Const KEYEVENTF_EXTENDEDKEY = &H1
    11. Private Const KEYEVENTF_KEYUP = &H2
    12. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    13. Private Sub SetKeyState(ByVal Key As Long, ByVal State As Boolean)
    14.  
    15.   Call keybd_event(Key, MapVirtualKey(Key, 0), _
    16.      KEYEVENTF_EXTENDEDKEY Or 0, 0)
    17.  
    18.     Call keybd_event(Key, MapVirtualKey(Key, 0), _
    19.      KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
    20.  
    21. End Sub
    22.  
    23. Private Property Get CapsLock() As Boolean
    24.  
    25.   CapsLock = GetKeyState(KeyCodeConstants.vbKeyCapital) = 1
    26.  
    27. End Property
    28.  
    29. Private Property Let CapsLock(ByVal Value As Boolean)
    30.  
    31.   Call SetKeyState(KeyCodeConstants.vbKeyCapital, Value)
    32.  
    33. End Property
    34.  
    35. Private Property Get NumLock() As Boolean
    36.  
    37.   NumLock = GetKeyState(KeyCodeConstants.vbKeyNumlock) = 1
    38.  
    39. End Property
    40.  
    41. Private Property Let NumLock(ByVal Value As Boolean)
    42.  
    43.   Call SetKeyState(KeyCodeConstants.vbKeyNumlock, Value)
    44.  
    45. End Property
    46.  
    47. Private Property Get ScrollLock() As Boolean
    48.  
    49.   ScrollLock = GetKeyState(KeyCodeConstants.vbKeyScrollLock) = 1
    50.  
    51. End Property
    52.  
    53. Private Property Let ScrollLock(ByVal Value As Boolean)
    54.  
    55.   Call SetKeyState(KeyCodeConstants.vbKeyScrollLock, Value)
    56.  
    57. End Property
    58.  
    59.  
    60. Private Sub Command3_Click()
    61. 'Text1.SetFocus
    62. 'SendKeys "{CAPSLOCK}"
    63. CapsLock = Not CapsLock
    64. End Sub
    65.  
    66. Private Sub lblKey0_Click()
    67. Text1.SetFocus
    68. SendKeys "0"
    69. End Sub
    70.  
    71. Private Sub lblKey1_Click()
    72. Text1.SetFocus
    73. SendKeys "1"
    74. End Sub
    75.  
    76. Private Sub lblKey2_Click()
    77. Text1.SetFocus
    78. SendKeys "2"
    79. End Sub
    80.  
    81. Private Sub lblKey3_Click()
    82. Text1.SetFocus
    83. SendKeys "3"
    84. End Sub
    85.  
    86. Private Sub lblKey4_Click()
    87. Text1.SetFocus
    88. SendKeys "4"
    89. End Sub
    90.  
    91. Private Sub lblKey5_Click()
    92. Text1.SetFocus
    93. SendKeys "5"
    94. End Sub
    95.  
    96. Private Sub lblKey6_Click()
    97. Text1.SetFocus
    98. SendKeys "6"
    99. End Sub
    100.  
    101. Private Sub lblKey7_Click()
    102. Text1.SetFocus
    103. SendKeys "7"
    104. End Sub
    105.  
    106. Private Sub lblKey8_Click()
    107. Text1.SetFocus
    108. SendKeys "8"
    109. End Sub
    110.  
    111. Private Sub lblKey9_Click()
    112. Text1.SetFocus
    113. SendKeys "9"
    114. End Sub
    115.  
    116. Private Sub lblKeyBksp_Click()
    117. Text1.SetFocus
    118. SendKeys "{BACKSPACE}"
    119. End Sub
    120.  
    121.  
    122.  
    123. Private Sub lblKeyDecimal_Click()
    124. Text1.SetFocus
    125. SendKeys "."
    126. End Sub
    127.  
    128. Private Sub lblKeyDivide_Click()
    129. Text1.SetFocus
    130. SendKeys "{/}"
    131. End Sub
    132.  
    133. Private Sub lblKeyEnter_Click()
    134. Text1.SetFocus
    135. SendKeys "{ENTER}"
    136. End Sub
    137.  
    138. Private Sub lblKeyMultiply_Click()
    139.  'Text1.SetFocus
    140.  SendKeys "{*}"
    141. End Sub
    142.  
    143. Private Sub lblKeyNumLock_Click()
    144. 'SendKeys "{NUMLOCK}"
    145. NumLock = Not NumLock
    146. End Sub
    147.  
    148. Private Sub lblKeyPlus_Click()
    149. Text1.SetFocus
    150. SendKeys "{+}"
    151. End Sub

  6. #6

  7. #7

  8. #8
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Numpad

    Quote Originally Posted by potatocake

    How do i make it multiline?

    change its property to ture
    Attached Images Attached Images  
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Re: Numpad

    Thanks Martin,

    Works like a charm

    Thats only leaving the enter button, how do i make it multiline? Do program it the same way you've done with numlock/capslock? Sorry this is my first time with the sendkeys function.

    BTW you should always use Option Explicit
    I will keep tat advice in mind

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Re: Numpad

    oops sorry didnt see ur post before i posted. thanks a bunch

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Numpad

    Both wiz and I showed you how to make it multipline but you may not want to in any case. I say that because I don't think that that would be consistant with a calculator.

    In any case have you thought about how you are going to solve the equations? One way to do that is to add a reference in your app to the Microsoft Script Control 1.0 and then do this

    VB Code:
    1. Private Sub lblKeyEnter_Click()
    2. 'Text1.SetFocus
    3. Dim oSC As New ScriptControl
    4.    
    5.     oSC.Language = "VBScript"
    6.     Text1.Text = Text1.Text & " = " & oSC.eval(Text1.Text)
    7.  
    8.  
    9. SendKeys "{ENTER}"
    10. End Sub

  12. #12
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: [RESOLVED] Numpad

    i don't understand, what are you having problem with?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Re: [RESOLVED] Numpad

    In any case have you thought about how you are going to solve the equations?
    Hrrm I haven't really thought about doing the calculations wanted more of an touchscreen numpad which may or may not do calculations but, thats a really good idea to have it jus in case.

    One way to do that is to add a reference in your app to the Microsoft Script Control 1.0
    how do i add this reference? Tried checking the Add Ins Manager but cant find it. Sorry if im a little thick headed this morning...hehe

  14. #14

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Re: [RESOLVED] Numpad

    ooo...Thanks again

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