Oppure

Loading
02/10/06 14:31
PATATONJ
ciao a tutti,

ho bisogno di intercettare tutti i tasti premuti al di fuori del mio applicativo per scriverli su un file di testo. dopodi chè farli ripetere in automatico. mi serve perche devo ripetere l'operazione tot volte e se lo faccio a mano divento cretino.

qualcuno mi puo aiutare?
:-?:-?
aaa
03/10/06 18:39
Reese
Intanto per "catturare" i tasti premuti al di fuori del tuo applicativo, usa GetAsyncKey. Poi è tutta discesa :D.
aaa
03/10/06 23:51
pierotofy
Gli hook di sistema sono complessi da usare e permettono maggiore flessibilità, ma nel tuo caso come ti hanno già suggerito ti conviene dare uno sguardo alla funzione GetAsyncKeyState.
Il mio blog: piero.dev
04/10/06 7:29
PATATONJ
Grazie mille a tutti e due.
Ho gia provato con ambedue gli eventi ma sono limitati ai soli tasti alfabetici. I tasti come la virgola, l'underscore, il pipe e altri non vengono intercettati in quanto privi di codice costante.
Una hook mi intercetterebbe tutti i tasti premuti e ne ho costruita una ma mi funziona solo sulla mia applicazione non esternamente.

:(
non sapete se è possibile renderla attiva a livello globale?
aaa
21/10/06 15:01
Belial King
Usa le DirectX...
Sul menu "Progetto" seleziona "Riferimenti..." quindi seleziona "DirectX 8 for Visual Basic Type Library" poi incolla il seguente codice...

Public MyHandle As Long
Public Dx As New DirectX8
Public Di As DirectInput8
Public DiDevK As DirectInputDevice8
Public DiDevM As DirectInputDevice8
Public KeyboardState As DIKEYBOARDSTATE
Public MouseState As DIMOUSESTATE
Public tmS(256), tmI, tmE, tmT, lst_tmE, tmSM(256), tmEM, tmTM, Rip
Public nKey(256) As String
Public nMouse(256) As String

Private Sub Form_Load()
nKey(11) = "0"
nKey(2) = "1"
nKey(3) = "2"
nKey(4) = "3"
nKey(5) = "4"
nKey(6) = "5"
nKey(7) = "6"
nKey(8) = "7"
nKey(9) = "8"
nKey(10) = "9"
nKey(30) = "A"
nKey(115) = "ABNT_C1"
nKey(126) = "ABNT_C2"
nKey(78) = "ADD"
nKey(40) = "APOSTROPHE"
nKey(221) = "APPS"
nKey(145) = "AT"
nKey(150) = "AX"
nKey(48) = "B"
nKey(14) = "BACK"
nKey(43) = "BACKSLASH"
nKey(14) = "BACKSPACE"
nKey(46) = "C"
nKey(161) = "CALCULATOR"
nKey(58) = "CAPITAL"
nKey(58) = "CAPSLOCK"
nKey(144) = "CIRCUMFLEX"
nKey(146) = "COLON"
nKey(51) = "COMMA"
nKey(121) = "CONVERT"
nKey(32) = "D"
nKey(83) = "DECIMAL"
nKey(211) = "DELETE"
nKey(181) = "DIVIDE"
nKey(208) = "DOWN"
nKey(208) = "DOWNARROW"
nKey(18) = "E"
nKey(207) = "END"
nKey(13) = "EQUALS"
nKey(1) = "ESCAPE"
nKey(33) = "F"
nKey(59) = "F1"
nKey(60) = "F2"
nKey(61) = "F3"
nKey(62) = "F4"
nKey(63) = "F5"
nKey(64) = "F6"
nKey(65) = "F7"
nKey(66) = "F8"
nKey(67) = "F9"
nKey(68) = "F10"
nKey(87) = "F11"
nKey(88) = "F12"
nKey(100) = "F13"
nKey(101) = "F14"
nKey(102) = "F15"
nKey(34) = "G"
nKey(41) = "GRAVE"
nKey(35) = "H"
nKey(199) = "HOME"
nKey(23) = "I"
nKey(210) = "INSERT"
nKey(36) = "J"
nKey(37) = "K"
nKey(112) = "KANA"
nKey(148) = "KANJI"
nKey(38) = "L"
nKey(56) = "LALT"
nKey(26) = "LBRACKET"
nKey(29) = "LCONTROL"
nKey(203) = "LEFT"
nKey(203) = "LEFTARROW"
nKey(56) = "LMENU"
nKey(42) = "LSHIFT"
nKey(219) = "LWIN"
nKey(50) = "M"
nKey(236) = "MAIL"
nKey(237) = "MEDIASELECT"
nKey(164) = "MEDIASTOP"
nKey(12) = "MINUS"
nKey(55) = "MULTIPLY"
nKey(160) = "MUTE"
nKey(235) = "MYCOMPUTER"
nKey(49) = "N"
nKey(209) = "NEXT"
nKey(153) = "NEXTTRACK"
nKey(123) = "NOCONVERT"
nKey(69) = "NUMLOCK"
nKey(82) = "NUMPAD0"
nKey(79) = "NUMPAD1"
nKey(80) = "NUMPAD2"
nKey(81) = "NUMPAD3"
nKey(75) = "NUMPAD4"
nKey(76) = "NUMPAD5"
nKey(77) = "NUMPAD6"
nKey(71) = "NUMPAD7"
nKey(72) = "NUMPAD8"
nKey(73) = "NUMPAD9"
nKey(179) = "NUMPADCOMMA"
nKey(156) = "NUMPADENTER"
nKey(141) = "NUMPADEQUALS"
nKey(74) = "NUMPADMINUS"
nKey(83) = "NUMPADPERIOD"
nKey(78) = "NUMPADPLUS"
nKey(181) = "NUMPADSLASH"
nKey(55) = "NUMPADSTAR"
nKey(24) = "O"
nKey(86) = "OEM_102"
nKey(25) = "P"
nKey(197) = "PAUSE"
nKey(52) = "PERIOD"
nKey(209) = "PGDN"
nKey(201) = "PGUP"
nKey(162) = "PLAYPAUSE"
nKey(222) = "POWER"
nKey(144) = "PREVTRACK"
nKey(201) = "PRIOR"
nKey(16) = "Q"
nKey(19) = "R"
nKey(184) = "RALT"
nKey(27) = "RBRACKET"
nKey(157) = "RCONTROL"
nKey(28) = "RETURN"
nKey(205) = "RIGHT"
nKey(205) = "RIGHTARROW"
nKey(184) = "RMENU"
nKey(54) = "RSHIFT"
nKey(220) = "RWIN"
nKey(31) = "S"
nKey(70) = "SCROLL"
nKey(39) = "SEMICOLON"
nKey(53) = "SLASH"
nKey(223) = "SLEEP"
nKey(57) = "SPACE"
nKey(149) = "STOP"
nKey(74) = "SUBTRACT"
nKey(183) = "SYSRQ"
nKey(20) = "T"
nKey(15) = "TAB"
nKey(22) = "U"
nKey(147) = "UNDERLINE"
nKey(151) = "UNLABELED"
nKey(200) = "UP"
nKey(200) = "UPARROW"
nKey(47) = "V"
nKey(174) = "VOLUMEDOWN"
nKey(176) = "VOLUMEUP"
nKey(17) = "W"
nKey(227) = "WAKE"
nKey(234) = "WEBBACK"
nKey(230) = "WEBFAVORITES"
nKey(233) = "WEBFORWARD"
nKey(178) = "WEBHOME"
nKey(231) = "WEBREFRESH"
nKey(229) = "WEBSEARCH"
nKey(232) = "WEBSTOP"
nKey(45) = "X"
nKey(21) = "Y"
nKey(125) = "YEN"
nKey(44) = "Z"
nMouse(0) = "MOUSE_LBUTTON"
nMouse(1) = "MOUSE_RBUTTON"
nMouse(2) = "MOUSE_CBUTTON"
For a = 0 To 255
tmS(i) = 0
tmSM(0) = 0
Next a
tmE = 0
tmT = 0
lst_tmE = 0
Rip = 0
tmI = Timer
AppPath = App.Path
If righr(AppPath, 1) <> "\" Then AppPath = AppPath + "\"

'DirectInput Initialize
Set Di = Dx.DirectInputCreate()
Set DiDevK = Di.CreateDevice("GUID_SysKeyboard";)
Set DiDevM = Di.CreateDevice("GUID_SysMouse";)
DiDevK.SetCommonDataFormat (CONST_DICOMMONDATAFORMATS.DIFORMAT_KEYBOARD)
DiDevM.SetCommonDataFormat (CONST_DICOMMONDATAFORMATS.DIFORMAT_MOUSE)
MyHandle = Me.hWnd
DiDevK.SetCooperativeLevel MyHandle, CONST_DISCLFLAGS.DISCL_NONEXCLUSIVE Or DxVBLibA.CONST_DISCLFLAGS.DISCL_BACKGROUND
DiDevK.Acquire
DiDevM.SetCooperativeLevel MyHandle, CONST_DISCLFLAGS.DISCL_NONEXCLUSIVE Or DxVBLibA.CONST_DISCLFLAGS.DISCL_BACKGROUND
DiDevM.Acquire
Form1.Show
Form1.Hide
On Error GoTo cErr

'Loop
myTime = CStr(Time)
Do While Ending = False
myClipboard = Clipboard.GetText
DiDevK.GetDeviceStateKeyboard KeyboardState
DiDevM.GetDeviceStateMouse MouseState
Open AppPath + CStr(Format(Date, "dd_mm_yyyy";)) + ".txt" For Append As #1
If myTime <> "" Then Print #1, "TIME:" + myTime
myTime = ""
cTimer = Timer
If myClipboard <> oldClipboard Then Print #1, CStr(Format(TimeSerial(0, 0, Int(cTimer - tmI)), "hh:mm:ss";)) + CStr(Format((cTimer - tmI) - Int(cTimer - tmI), "#.00";)) + ";CLIPBOARD:" + myClipboard + Chr(10) + Chr(13)
oldClipboard = myClipboard
cTimer = Timer
For i = 0 To 2
If tmSM(i) > 0 And MouseState.Buttons(i) = 0 Then
tmEM = cTimer - tmI
tmTM = tmEM - tmSM(i)
tmSFM = CStr(Format(TimeSerial(0, 0, Int(tmSM(i))), "hh:mm:ss";)) + CStr(Format(tmSM(i) - Int(tmSM(i)), "#.00";))
tmEFM = CStr(Format(TimeSerial(0, 0, tmEM), "hh:mm:ss";)) + CStr(Format(tmEM - Int(tmEM), "#.00";))
tmTFM = CStr(Format(TimeSerial(0, 0, tmTM), "hh:mm:ss";)) + CStr(Format(tmTM - Int(tmTM), "#.00";))
Print #1, (CStr(tmSFM) + ";" + CStr(tmEFM) + ";" + CStr(tmTFM) + ";" + nMouse(i)) + Chr(10) + Chr(13)
tmSM(i) = 0
End If
If MouseState.Buttons(i) = 128 Then
If tmSM(i) = 0 Then tmSM(i) = cTimer - tmI
End If
Next i
cTimer = Timer
For i = 0 To 255
If tmS(i) > 0 And KeyboardState.Key(i) = 0 Then
tmE = cTimer - tmI
tmT = tmE - tmS(i)
If tmT > 0.5 Then Rip = Int((tmT - 0.5) * 29.4) + 2
tmSF = CStr(Format(TimeSerial(0, 0, Int(tmS(i))), "hh:mm:ss";)) + CStr(Format(tmS(i) - Int(tmS(i)), "#.00";))
tmEF = CStr(Format(TimeSerial(0, 0, tmE), "hh:mm:ss";)) + CStr(Format(tmE - Int(tmE), "#.00";))
tmTF = CStr(Format(TimeSerial(0, 0, tmT), "hh:mm:ss";)) + CStr(Format(tmT - Int(tmT), "#.00";))
Rip = Format(Rip, "000000";)
If lst_tmE > tmS(i) Then addS = "+"
lst_tmE = tmE
Print #1, (CStr(tmSF) + ";" + CStr(tmEF) + ";" + CStr(tmTF) + ";" + CStr(Rip) + ";" + nKey(i)) + addS + Chr(10) + Chr(13)
tmS(i) = 0
tmE = 0
tmT = 0
Rip = 0
addS = ""
End If
If KeyboardState.Key(i) = 128 Then
If tmS(i) = 0 Then tmS(i) = cTimer - tmI
End If
Next i
Close #1
DoEvents
Loop

cErr:
On Error GoTo cErr
Resume
End Sub

aaa