huabao 发表于 2010-11-27 19:09:18

一个软键盘代码,请帮忙找下那里有问题

代码如下,问题是点击软键两次之间的间隔有点长,还不能点着键不放连续输入,请大家帮忙看看。原码在下面
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = "X:" & X & "Y:" & Y
Label2.Caption = "X:" & X / Screen.TwipsPerPixelX & "Y:" & Y / Screen.TwipsPerPixelY
If X < 38 * Screen.TwipsPerPixelX Then'左侧小格段

      If Y > 2 * Screen.TwipsPerPixelY And Y < 19 * Screen.TwipsPerPixelY Then '+
                  With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
                  Text1.Text = Text1.Text & "+"
      End If
      If Y > 19 * Screen.TwipsPerPixelX And Y < 38 * Screen.TwipsPerPixelY Then '-
                  With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX + 19 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2 + 19, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
                  Text1.Text = Text1.Text & "-"
      End If
      If Y > 38 * Screen.TwipsPerPixelX And Y < 57 * Screen.TwipsPerPixelY Then '*
                     With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX + 38 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2 + 38, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
                  Text1.Text = Text1.Text & "×"
      End If
      If Y > 57 * Screen.TwipsPerPixelY And Y < 76 * Screen.TwipsPerPixelY Then '/
                  With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX + 57 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2 + 57, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
                  Text1.Text = Text1.Text & "÷"
      End If
      If Y > 76 * Screen.TwipsPerPixelX And Y < 95 * Screen.TwipsPerPixelY Then '=
                  With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX + 76 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2 + 76, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
                  Text1.Text = Text1.Text & "="
      End If
      If Y > 95 * Screen.TwipsPerPixelX And Y < 114 * Screen.TwipsPerPixelY Then '.
                  With Picture4
                  .Width = 34 * Screen.TwipsPerPixelX
                  .Height = 19 * Screen.TwipsPerPixelY
                  .Left = 2 * Screen.TwipsPerPixelY
                  .Top = 3 * Screen.TwipsPerPixelX + 95 * Screen.TwipsPerPixelX
                  End With
                  BitBlt Picture4.hDC, 0, 0, 38, 19, Picture3.hDC, 1, 2 + 95, vbSrcCopy
                  With Picture4
                  .Visible = True
                  .Refresh
                  End With
      Text1.Text = ""
      End If
Else
      If X > 40 * Screen.TwipsPerPixelX And X < 90 * Screen.TwipsPerPixelX Then '第一大格段
                If Y > 2 * Screen.TwipsPerPixelY And Y < 36 * Screen.TwipsPerPixelY Then '1
                            With Picture4
                            .Width = 50 * Screen.TwipsPerPixelX
                            .Height = 36 * Screen.TwipsPerPixelY
                            .Left = 40 * Screen.TwipsPerPixelY
                            .Top = 2 * Screen.TwipsPerPixelX
                            End With
                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 40, 2, vbSrcCopy
                            With Picture4
                            .Visible = True
                            .Refresh
                            End With
                            Text1.Text = Text1.Text & "1"
                End If
                If Y > 36 * Screen.TwipsPerPixelY And Y < 72 * Screen.TwipsPerPixelY Then '4
                            With Picture4
                            .Width = 50 * Screen.TwipsPerPixelX
                            .Height = 36 * Screen.TwipsPerPixelY
                            .Left = 40 * Screen.TwipsPerPixelY
                            .Top = 2 * Screen.TwipsPerPixelX + 40 * Screen.TwipsPerPixelX
                            End With
                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 40, 2 + 40, vbSrcCopy
                            With Picture4
                            .Visible = True
                            .Refresh
                            End With
                            Text1.Text = Text1.Text & "4"
                End If
                If Y > 72 * Screen.TwipsPerPixelY And Y < 108 * Screen.TwipsPerPixelY Then '7
                            With Picture4
                            .Width = 50 * Screen.TwipsPerPixelX
                            .Height = 36 * Screen.TwipsPerPixelY
                            .Left = 40 * Screen.TwipsPerPixelY
                            .Top = 2 * Screen.TwipsPerPixelX + 80 * Screen.TwipsPerPixelX
                            End With
                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 40, 2 + 80, vbSrcCopy
                            With Picture4
                            .Visible = True
                            .Refresh
                            End With
                            Text1.Text = Text1.Text & "7"
                End If
      Else
                If X > 90 * Screen.TwipsPerPixelX And X < 140 * Screen.TwipsPerPixelX Then '第2大格段
                        If Y > 2 * Screen.TwipsPerPixelY And Y < 36 * Screen.TwipsPerPixelY Then '2
                                    With Picture4
                                    .Width = 50 * Screen.TwipsPerPixelX
                                    .Height = 36 * Screen.TwipsPerPixelY
                                    .Left = 90 * Screen.TwipsPerPixelY
                                    .Top = 2 * Screen.TwipsPerPixelX
                                    End With
                                 BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 90, 2, vbSrcCopy
                                    With Picture4
                                    .Visible = True
                                    .Refresh
                                    End With
                                    Text1.Text = Text1.Text & "2"
                        End If
                        If Y > 36 * Screen.TwipsPerPixelY And Y < 72 * Screen.TwipsPerPixelY Then '5
                                    With Picture4
                                    .Width = 50 * Screen.TwipsPerPixelX
                                    .Height = 36 * Screen.TwipsPerPixelY
                                    .Left = 90 * Screen.TwipsPerPixelY
                                    .Top = 2 * Screen.TwipsPerPixelX + 40 * Screen.TwipsPerPixelX
                                    End With
                                 BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 90, 2 + 40, vbSrcCopy
                                    With Picture4
                                    .Visible = True
                                    .Refresh
                                    End With
                                    Text1.Text = Text1.Text & "5"
                        End If
                        If Y > 72 * Screen.TwipsPerPixelY And Y < 108 * Screen.TwipsPerPixelY Then '8
                                    With Picture4
                                    .Width = 50 * Screen.TwipsPerPixelX
                                    .Height = 36 * Screen.TwipsPerPixelY
                                    .Left = 90 * Screen.TwipsPerPixelY
                                    .Top = 2 * Screen.TwipsPerPixelX + 80 * Screen.TwipsPerPixelX
                                    End With
                                 BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 90, 2 + 80, vbSrcCopy
                                    With Picture4
                                    .Visible = True
                                    .Refresh
                                    End With
                                    Text1.Text = Text1.Text & "8"
                        End If
                Else
               
                        If X > 140 * Screen.TwipsPerPixelX And X < 190 * Screen.TwipsPerPixelX Then '第3大格段
                              If Y > 2 * Screen.TwipsPerPixelY And Y < 36 * Screen.TwipsPerPixelY Then '3
                                          With Picture4
                                          .Width = 50 * Screen.TwipsPerPixelX
                                          .Height = 36 * Screen.TwipsPerPixelY
                                          .Left = 140 * Screen.TwipsPerPixelY
                                          .Top = 2 * Screen.TwipsPerPixelX
                                          End With
                                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 140, 2, vbSrcCopy
                                          With Picture4
                                          .Visible = True
                                          .Refresh
                                          End With
                                          Text1.Text = Text1.Text & "3"
                              End If
                              If Y > 36 * Screen.TwipsPerPixelY And Y < 72 * Screen.TwipsPerPixelY Then '6
                                          With Picture4
                                          .Width = 50 * Screen.TwipsPerPixelX
                                          .Height = 36 * Screen.TwipsPerPixelY
                                          .Left = 140 * Screen.TwipsPerPixelY
                                          .Top = 2 * Screen.TwipsPerPixelX + 40 * Screen.TwipsPerPixelX
                                          End With
                                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 140, 2 + 40, vbSrcCopy
                                          With Picture4
                                          .Visible = True
                                          .Refresh
                                          End With
                                          Text1.Text = Text1.Text & "6"
                              End If
                              If Y > 72 * Screen.TwipsPerPixelY And Y < 108 * Screen.TwipsPerPixelY Then '9
                                          With Picture4
                                          .Width = 50 * Screen.TwipsPerPixelX
                                          .Height = 36 * Screen.TwipsPerPixelY
                                          .Left = 140 * Screen.TwipsPerPixelY
                                          .Top = 2 * Screen.TwipsPerPixelX + 80 * Screen.TwipsPerPixelX
                                          End With
                                           BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 140, 2 + 80, vbSrcCopy
                                          With Picture4
                                          .Visible = True
                                          .Refresh
                                          End With
                                          Text1.Text = Text1.Text & "9"
                              End If
                        Else
                              If X > 190 * Screen.TwipsPerPixelX Then '第4大格段
                                        If Y > 2 * Screen.TwipsPerPixelY And Y < 36 * Screen.TwipsPerPixelY Then 'C
                                                    With Picture4
                                                    .Width = 50 * Screen.TwipsPerPixelX
                                                    .Height = 36 * Screen.TwipsPerPixelY
                                                    .Left = 190 * Screen.TwipsPerPixelY
                                                    .Top = 2 * Screen.TwipsPerPixelX
                                                    End With
                                                   BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 190, 2, vbSrcCopy
                                                    With Picture4
                                                    .Visible = True
                                                    .Refresh
                                                    End With
                                                    If Text1.Text <> "" Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
                                        End If
                                        If Y > 36 * Screen.TwipsPerPixelY And Y < 72 * Screen.TwipsPerPixelY Then 'enter
                                                    With Picture4
                                                    .Width = 50 * Screen.TwipsPerPixelX
                                                    .Height = 36 * Screen.TwipsPerPixelY
                                                    .Left = 190 * Screen.TwipsPerPixelY
                                                    .Top = 2 * Screen.TwipsPerPixelX + 40 * Screen.TwipsPerPixelX
                                                    End With
                                                   BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 190, 2 + 40, vbSrcCopy
                                                    With Picture4
                                                    .Visible = True
                                                    .Refresh
                                                    End With
                                        End If
                                        If Y > 72 * Screen.TwipsPerPixelY And Y < 108 * Screen.TwipsPerPixelY Then '0
                                                    With Picture4
                                                    .Width = 50 * Screen.TwipsPerPixelX
                                                    .Height = 36 * Screen.TwipsPerPixelY
                                                    .Left = 190 * Screen.TwipsPerPixelY
                                                    .Top = 2 * Screen.TwipsPerPixelX + 80 * Screen.TwipsPerPixelX
                                                    End With
                                                   BitBlt Picture4.hDC, 0, 0, 50, 36, Picture3.hDC, 190, 2 + 80, vbSrcCopy
                                                    With Picture4
                                                    .Visible = True
                                                    .Refresh
                                                    End With
                                                    Text1.Text = Text1.Text & "0"
                                        End If
                              End If
                        End If


                End If

      End If


End If

End Sub

Private Sub Form_Load()
a = 0
   With Picture2
   .AutoRedraw = True
    .Width = 2928 '240 * Screen.TwipsPerPixelX
    .Height = 1464 '120 * Screen.TwipsPerPixelY
   End With
      With Picture1
      .Enabled = False
      .Visible = False
      .AutoRedraw = True
    .Width = 2928 '240 * Screen.TwipsPerPixelX
    .Height = 2968 '120 * Screen.TwipsPerPixelY
   End With
      With Picture3
      .Enabled = False
      .Visible = False
      .AutoRedraw = True
    .Width = 2928 '240 * Screen.TwipsPerPixelX
    .Height = 1464 '120 * Screen.TwipsPerPixelY
   End With
      With Picture4
      .AutoRedraw = True
   .Visible = False
    .Width = 0
    .Height = 0
    .Enabled = False
   End With
Picture1.Picture = LoadPicture("num1.bmp")
Picture1.Refresh
Text1.Text = ""
ini
End Sub

'大格宽49,高36
'小格宽38,高19
'绿大格X122Y40,下一个X+40,Y+50.绿小格X123,Y3.下一个X+19,Y+0


Private Sub ini() '初始化界面
            BitBlt Picture2.hDC, 0, 0, 240, 120, Picture1.hDC, 0, 0, vbSrcCopy
            Picture2.Refresh
            BitBlt Picture3.hDC, 0, 0, 240, 120, Picture1.hDC, 0, 120, vbSrcCopy
            Picture3.Refresh
End Sub



Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture4.Visible = False
End Sub

huabao 发表于 2010-11-28 11:04:38

帮忙看下,急

马大哈 发表于 2011-3-28 15:30:35

速度慢的原因是还有双击与单击事件在影响着,这个貌似没啥好办法.

至于连续按着不放也能自动出字符,需要你自己写代码实现,思路:

鼠标按下时记录数值,并启动定时器A,定时器A的时间就是判断连续按键的时间;

定时器A触发后,说明按下足够长的时间了,启动定时器B,进行连续输入字符.

鼠标抬起时,关闭定时器.
页: [1]
查看完整版本: 一个软键盘代码,请帮忙找下那里有问题