DESABILITAR O CTRL C E CTRL V PELO VB

FCCN 12/03/2010 18:00:06
#336830
Gostaria de saber como eu faço para desabilitar e habilitar teclas pelo VB.. por exemplo: CTRL + C e CTRL + V.
ERIVELTONVGA 13/03/2010 11:42:25
#336874
BOM DIA
tenta assim


coloca no evento keypress dos campos txt[ô]s assim como o exemplo abaixo


Private Sub txtirmao_KeyPress(KeyAscii As Integer)
[ô]converte as teclas para maiusculo
KeyAscii = Asc(UCase(Chr(KeyAscii)))

[ô]verifica se o control c ou control v foi acionado e bloqueia
If KeyAscii = 3 Then [ô]Definindo Botão De Control+C Em Caracteres ASCII
KeyAscii = 0 [ô]Definindo Que O Control+C Deve Representar No TextBox
MsgBox ([Ô]Impossível Copiar[Ô]), vbCritical [ô]Mensagem Ao Executar A Ação De Copiar
ElseIf KeyAscii = 22 Then [ô]Definindo O Botão De Control+V Em Caracteres ASCII
KeyAscii = 0 [ô]Definindo Botão Control+V Deve Representar No TextBox
MsgBox ([Ô]Impossível colar[Ô]), vbCritical [ô]Mensagem Ao Executar A Ação De Colar
End If

End Sub



espero ter ajudado.
Caso funcione não esqueca de encerrar o topico. valew

ERIVELTONVGA 13/03/2010 12:12:50
#336876
Resposta escolhida
OUTRA COISA VOCE PODE FAZER TAMBEM QUE ACABEI DE TESTAR, ISSO BLOQUEIA O BOTAO DIREITO DO MOUSE, AÍ O BLOQUEIO FICA EM 100%
SEGUE ABAIXO

OBSERVACAO COLOQUE NO FORM UM [Ô]TIMER[Ô] COM INTERVALO = 1 COMO SEGUE ABAIXO

COPIE TUDO QUE ESTA ABAIXO E COLE NO FORM EM [Ô][txt-color=#e80000]GENERAL[/txt-color][Ô]

==========================
[ô] << Bloquear botão direito do mouse >>
[ô] reconhece qual botão foi clicado e seu estado Down ou UP
Private Declare Function GetAsyncKeyState Lib [Ô]user32[Ô] (ByVal vKey As Long) As Integer

[ô] checa posição mouse e gera um clique/eventos no mouse
Private Declare Function GetCursorPos Lib _
[Ô]user32[Ô] (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib _
[Ô]user32[Ô] (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
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_MOVE = &H1 [ô] mouse move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 [ô] left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 [ô] left button up
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 [ô] right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 [ô] right button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 [ô] middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 [ô] middle button up
Private Const MOUSEEVENTF_WHEEL = &H800 [ô] wheel button rolled
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 [ô] absolute move

Private Type POINTAPI
X As Long
Y As Long
End Type

Dim pt As POINTAPI
Dim pts As POINTAPI
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single
[ô]FIM General form


[ô]INCLUA UM TIMER NO FORM COM INTERVALO = 1

Private Sub Timer1_Timer()

If GetAsyncKeyState(2) = 0 Then
[ô] clicou botão esquerdo e não faz nada
Else
[ô] clicou botão direito
[ô] Things are easier working in pixels.
Me.ScaleMode = vbPixels

[ô] mouse_event moves in a coordinate system where
[ô] (0, 0) is in the upper left corner and
[ô] (65535,65535) is in the lower right corner.

[ô] Get the current mouse coordinates and convert them into this new
[ô] system.GetCursorPos pt
cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)

[ô] Salva as coordenadas do mouse (NOVO)
pts.X = cur_x
pts.Y = cur_y

[ô] Convert the coordinates of the center of the form into this new
[ô] system.
pt.X = Me.ScaleLeft
pt.Y = Me.ScaleTop
[ô]pt.X = Me.ScaleWidth / 2
[ô]pt.Y = Me.ScaleHeight / 2
ClientToScreen Me.hwnd, pt
dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)

[ô] Move the mouse to its final destination and click it.
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE + _
MOUSEEVENTF_LEFTDOWN + _
MOUSEEVENTF_LEFTUP, _
dest_x, dest_y, 0, 0

[ô] move o mouse para a posição inicial (NOVO)
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE, _
pts.X, pts.Y, 0, 0
End If
End Sub


ESPERO TER AJUDADO + UM POUCO.
FCCN 15/03/2010 11:23:44
#336985
Citação:

:
OUTRA COISA VOCE PODE FAZER TAMBEM QUE ACABEI DE TESTAR, ISSO BLOQUEIA O BOTAO DIREITO DO MOUSE, AÍ O BLOQUEIO FICA EM 100%
SEGUE ABAIXO

OBSERVACAO COLOQUE NO FORM UM [Ô]TIMER[Ô] COM INTERVALO = 1 COMO SEGUE ABAIXO

COPIE TUDO QUE ESTA ABAIXO E COLE NO FORM EM [Ô][txt-color=#e80000]GENERAL[/txt-color][Ô]

==========================
[ô] << Bloquear botão direito do mouse >>
[ô] reconhece qual botão foi clicado e seu estado Down ou UP
Private Declare Function GetAsyncKeyState Lib [Ô]user32[Ô] (ByVal vKey As Long) As Integer

[ô] checa posição mouse e gera um clique/eventos no mouse
Private Declare Function GetCursorPos Lib _
[Ô]user32[Ô] (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib _
[Ô]user32[Ô] (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
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_MOVE = &H1 [ô] mouse move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 [ô] left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 [ô] left button up
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 [ô] right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 [ô] right button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 [ô] middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 [ô] middle button up
Private Const MOUSEEVENTF_WHEEL = &H800 [ô] wheel button rolled
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 [ô] absolute move

Private Type POINTAPI
X As Long
Y As Long
End Type

Dim pt As POINTAPI
Dim pts As POINTAPI
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single
[ô]FIM General form


[ô]INCLUA UM TIMER NO FORM COM INTERVALO = 1

Private Sub Timer1_Timer()

If GetAsyncKeyState(2) = 0 Then
[ô] clicou botão esquerdo e não faz nada
Else
[ô] clicou botão direito
[ô] Things are easier working in pixels.
Me.ScaleMode = vbPixels

[ô] mouse_event moves in a coordinate system where
[ô] (0, 0) is in the upper left corner and
[ô] (65535,65535) is in the lower right corner.

[ô] Get the current mouse coordinates and convert them into this new
[ô] system.GetCursorPos pt
cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)

[ô] Salva as coordenadas do mouse (NOVO)
pts.X = cur_x
pts.Y = cur_y

[ô] Convert the coordinates of the center of the form into this new
[ô] system.
pt.X = Me.ScaleLeft
pt.Y = Me.ScaleTop
[ô]pt.X = Me.ScaleWidth / 2
[ô]pt.Y = Me.ScaleHeight / 2
ClientToScreen Me.hwnd, pt
dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)

[ô] Move the mouse to its final destination and click it.
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE + _
MOUSEEVENTF_LEFTDOWN + _
MOUSEEVENTF_LEFTUP, _
dest_x, dest_y, 0, 0

[ô] move o mouse para a posição inicial (NOVO)
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE, _

pts.X, pts.Y, 0, 0
End If
End Sub


ESPERO TER AJUDADO + UM POUCO.





OK. Ajudou-me em partes.

Por exemplo: Quando eu clicar no botão, enquanto ele tá processando um relatório eu posso desabilitar o CTRC+C e CTRV+V ???
MARCIO.TEIXEIRA 15/03/2010 11:34:48
#336986
Tenta o seguinte ai:

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift = vbCtrlMask And (Chr(KeyCode) = [Ô]v[Ô] Or Chr(KeyCode) = [Ô]V[Ô])) Or (Shift = vbShiftMask And KeyCode = vbKeyInsert) Then
Text1.Locked = True
Else
Text1.Locked = False
End If
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Text1.Locked = True
Else
Text1.Locked = False
End If
End Sub
SACOFRITO 16/03/2010 08:51:05
#337054
erivelton

gostei do código, to começando a programar e achei interessante...mas uma coisa q reparei. com o intervalo do timer em 1 segundo, da tempo se a pessoa for rápida, em clicar em alguma coisa...
entao eu reduzi o tempo p 500 ms
ta aí uma opniao minha :p

ah otra coisa, mas eu achei tb muito chato, isso de [ô]jogar[ô] o mouse pro topo da tela
ERIVELTONVGA 16/03/2010 09:54:29
#337064
sacofrito bom dia

eu sei que é chato. é que utilizo este codigo pra outra funcao, é um jogo que estou desenvolvendo onde quem clica na resposta errada ele joga para o canto central e a pessoa tem que comecar tudo de novo.rsrs sou mal. rsrs

e o colega FCCN perguntou como faz para bloquear o control+c e control+v, eu so complementei com o botao direito do mouse, pois era importante dependendo do uso. beleza?
MARCIO.TEIXEIRA 16/03/2010 10:49:40
#337070
Terá quer bloquear (Ctrl + Insert) e (Shift + Insert) também, fiz alguns testes no exemplo que passei e bloqueou
Tópico encerrado , respostas não são mais permitidas