powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Как поставить указатель мыши туда же, где курсор
5 сообщений из 5, страница 1 из 1
Как поставить указатель мыши туда же, где курсор
    #33789958
2AN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Как поставить указатель мыши туда же, где курсор?
...
Рейтинг: 0 / 0
Как поставить указатель мыши туда же, где курсор
    #33790459
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Невинный с виду вопрос...
Что имеется ввиду под "туда же"? Текстовое поле, находящееся в фокусе? Точная позиция курсора в этом поле?

Вот модуль, содержащий процедуру, которая центрирует указатель мыши на таком поле:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
Option Explicit

Private Declare Sub mouse_event Lib "user32" ( _
   ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
   ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 '  absolute move
Private Const MOUSEEVENTF_MOVE = &H1        '  mouse move

Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" ( _
   ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Const SPI_GETMOUSE =  3 
Private Const SPI_SETMOUSE =  4 
Private Const SPI_GETMOUSESPEED =  112 
Private Const SPI_SETMOUSESPEED =  113 
Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_SENDCHANGE = SPIF_SENDWININICHANGE
Private Declare Function SystemParametersInfo Lib "user32" _
   Alias "SystemParametersInfoA" ( _
   ByVal uAction As Long, ByVal uParam As Long, _
   ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

Public Sub CenterOnActiveTextBox()
 'Q193003
 Dim hWndActive As Long
 Dim rc As RECT
 Dim oldAccel( 0  To  2 ) As Long
 Dim newAccel( 0  To  2 ) As Long
 Dim oldSpeed As Long
 Dim newSpeed As Long
    
 On Error GoTo EH_CenterOnActiveTextBox
 If TypeOf Screen.ActiveControl Is TextBox Then
    hWndActive = GetFocus()
    GetWindowRect hWndActive, rc
    
    'The following values set mouse ballistics to 1 mickey/pixel.
    newSpeed =  1 
    
    'Save the Current Mouse Acceleration Constants
    SystemParametersInfo SPI_GETMOUSE,  0 , oldAccel( 0 ),  0 
    SystemParametersInfo SPI_GETMOUSESPEED,  0 , oldSpeed,  0 
    
    'Set the new Mouse Acceleration Constants (Disabled).
    SystemParametersInfo SPI_SETMOUSE,  0 , newAccel( 0 ), SPIF_SENDCHANGE
    SystemParametersInfo SPI_SETMOUSESPEED,  0 , newSpeed, SPIF_SENDCHANGE
   
    ' Move cursor to UL of primary monitor (origin).
    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE,  0 ,  0 ,  0 ,  0 
   
    'Move the cursor to the desired coordinates.
    'Если не устраивает центр, здесь надо вычислить новые координаты
    mouse_event MOUSEEVENTF_MOVE, (rc.Left + rc.Right) /  2 , _
                (rc.Top + rc.Bottom) /  2 ,  0 ,  0 
   
    ' Restore the old Mouse Acceleration Constants.
    SystemParametersInfo SPI_SETMOUSE,  0 , oldAccel( 0 ), SPIF_SENDCHANGE
    SystemParametersInfo SPI_SETMOUSESPEED,  0 , oldSpeed, SPIF_SENDCHANGE
 End If
EH_CenterOnActiveTextBox:
 On Error GoTo  0 
End Sub
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
Как поставить указатель мыши туда же, где курсор
    #40027957
uum
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
uum
Гость
Бенедикт
Невинный с виду вопрос...
Потребовалось ставить указатель мыши рядом с каждым редактируемым текст- или комбо-боксом, а mouse_event, говорят, устарела.
Попробовал: действительно 64-bit офис не любит :( Ну да ладно, устарела и устарела, бывает.
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
Option Explicit

#If VBA7 Then
    Declare PtrSafe Function GetFocus Lib "user32" () As LongPtr
#Else
    Declare Function GetFocus Lib "user32" () As Long
#End If

#If VBA7 Then
    Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As RECT) As Long
#Else
    Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
#End If

    Private Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
    End Type

#If VBA7 Then
    Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#Else
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#End If

Public Sub RightOnActiveComboBox()
On Error GoTo EH_RightOnActiveComboBox

    Dim rc As RECT
    Dim x As Long
    Dim y As Long
    
    #If VBA7 Then 
        Dim hWndActive As LongPtr
    #Else
        Dim hWndActive As Long
    #End If

    hWndActive = GetFocus()
    GetWindowRect hWndActive, rc
                
    x = rc.Right + IIf(TypeOf Screen.ActiveControl Is ComboBox, 23, 6)
    y = (rc.Top + rc.Bottom) / 2
    Call SetCursorPos(x, y)

EH_RightOnActiveComboBox:
 On Error GoTo 0
End Sub

Пример использования:
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err

    If Shift = 0 Then
        If Screen.ActiveControl.ControlType = acTextBox _
            Or Screen.ActiveControl.ControlType = acComboBox Then
                Call RightOnActiveComboBox
        End If
    End If

Err: End Sub
...
Рейтинг: 0 / 0
Как поставить указатель мыши туда же, где курсор
    #40027974
Фотография Панург
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
как-то так...
uum
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
Option Explicit

    Private Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
    End Type

#If VBA7 Then
    Declare PtrSafe Function GetFocus Lib "user32"() As LongPtr
    Declare PtrSafe Function GetWindowRect Lib "user32"(ByVal hwnd As LongPtr, lpRect As RECT) As Long
    Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#Else
    Declare Function GetFocus Lib "user32" () As Long
    Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#End If
...

...
Рейтинг: 0 / 0
Как поставить указатель мыши туда же, где курсор
    #40027986
uum
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
uum
Гость
Панург, истесс-с-но. Спасибо.
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Как поставить указатель мыши туда же, где курсор
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]