VB 怎样获取键鼠无动作时间 (100分送上)

VB 怎样获取键鼠无动作时间 (100分送上),第1张

问题一:

窗体上画出一个labe1和一个timer1,timer周期设置为1000

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Timer1_Timer()

Label1Caption = "系统启动" & GetTickCount() / 1000 & "秒。折合为" & (GetTickCount() / 1000) / 60 & "分" & (GetTickCount() / 1000) / 3600 & "小时"

End Sub

GetTickCount 函数用来获取系统启动的毫秒数。

问题二:

在窗体上画出一个timer1,timer周期设置为1000

Option Explicit

Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean

Private Declare Function GetTickCount Lib "kernel32" () As Long

Dim lTime As LASTINPUTINFO

Private Type LASTINPUTINFO

cbSize As Long

dwTime As Long

End Type

Private Sub Form_Load()

Timer1Interval = 1000

lTimecbSize = Len(lTime)

End Sub

Private Sub Timer1_Timer()

If GetLastInputInfo(lTime) Then

If (GetTickCount - lTimedwTime) / 1000 >= 5 Then'发现5秒内没有输入就d出提示

MsgBox "在规定时间内无 *** 作,执行命令"

End If

End If

End Sub

GetLastInputInfo函数的作用是获取系统空闲时间,也就是最后一次输入或者移动鼠标的时间到现在有多少毫秒。

问题三:

Private Sub Timer1_Timer()

Text3Text = Format(Now, "YYYY,MM,DD,hh,mm,ss,")

End Sub

窗体上画出Text1 Text2 Text3和Timer1 Timer2 Timer3

完整代码如下:

Option Explicit

Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean

Private Declare Function GetTickCount Lib "kernel32" () As Long

Dim lTime As LASTINPUTINFO

Private Type LASTINPUTINFO

cbSize As Long

dwTime As Long

End Type

Private Sub Timer1_Timer()

Text1Text = GetTickCount() / 1000 / 3600 & "," & GetTickCount() / 60000 & " ," & (GetTickCount() / 1000)

End Sub

Private Sub Form_Load()

Timer1Interval = 1000

Timer2Interval = 1000

Timer3Interval = 1000

lTimecbSize = Len(lTime)

End Sub

Private Sub Timer2_Timer()

If GetLastInputInfo(lTime) Then

Text2Text = (GetTickCount - lTimedwTime) / 1000 / 3600 & "," & (GetTickCount - lTimedwTime) / 60000 & "," & (GetTickCount - lTimedwTime) / 1000

End If

End Sub

Private Sub Timer3_Timer()

Text3Text = Format(Now, "YYYY,MM,DD,hh,mm,ss,")

End Sub

人品好,不复制。

希望能帮你解决问题

总体给你整理一下

可以禁止修改系统时间即可,代码如下,源码可以发给你,你的邮箱是?窗体form1(需要一个timer控件,interval=1000):

窗体代码Private Sub Form_Load()

Timer1_Timer

RegisterWindow Mehwnd '为窗口设置子类

End SubPrivate Sub Form_Unload(Cancel As Integer)

unRegisterWindow Mehwnd '取消窗口的子类

End SubPrivate Sub Timer1_Timer()

OldTime = Now

End Sub'模块modle1:Option Explicit

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long

Public OldTime As String

Public ChangeFlag As Boolean

Public Const WM_TIMECHANGE As Long = &H1E '当系统的时间变化时发送此消息给所有顶级窗口

Public oldproc As Long

Private Type SYSTEMTIME

wYear As Integer

wMonth As Integer

wDayOfWeek As Integer

wDay As Integer

wHour As Integer

wMinute As Integer

wSecond As Integer

wMilliseconds As Integer

End Type

Private Declare Function SetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As LongPublic Function RegisterWindow(hwnd As Long) As Long

If hwnd <> 0 Then

oldproc = SetWindowLong(hwnd, -4, AddressOf WinProc)

End If

End Function

Public Function unRegisterWindow(hwnd As Long) As LongIf hwnd <> 0 Then

SetWindowLong hwnd, -4, oldproc

End IfEnd Function

Public Function WinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal lpara As Long, ByVal wpara As Long) As LongDim i, myttIf msg = WM_TIMECHANGE And ChangeFlag = False Then '系统时间被修改了而且不是本程序修改的ChangeFlag = True '本程序要修改系统时间Call SetToOldTime '修改系统时间Exit FunctionEnd If

ChangeFlag = FalseWinProc = CallWindowProc(oldproc, hwnd, msg, lpara, wpara)

End Function

Public Function SetToOldTime() As String '将时间恢复到设置前的状态

Dim tmp As String

tmp = OldTime '从保存的时间中取出修改前的系统时间

Dim lpSystemTime As SYSTEMTIME

lpSystemTimewYear = Year(tmp) '取出年份

lpSystemTimewMonth = Month(tmp) '取出月份

lpSystemTimewDayOfWeek = -1

lpSystemTimewDay = Day(tmp) '取出日

lpSystemTimewHour = Hour(tmp) '取出小时

lpSystemTimewMinute = Minute(tmp) '取出分钟

lpSystemTimewSecond = Second(tmp) '取出秒

lpSystemTimewMilliseconds = 0

'set the new time

SetLocalTime lpSystemTimeEnd Function

一、获取选中的文字

使用windowgetSelection()toString()方法来获取选中的文字,在选中文字鼠标松开后会获取到选中的文字:

<p>可以选中一些文本</p>

<script type="text/javascript">

let selected = windowgetSelection()toString();

consolelog(selected);

if(selected != '' && selected != null){

windowalert('要百度搜索吗');

}

</script>

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

二、让内容可编辑

第一步:为元素设置contenteditable属性并赋值为true,让元素具有可编辑功能,当将其值赋值为false时不可编辑;

第二步:伪元素设置spellcheck属性,并赋值为true,即开启拼写检查,设置值为false时关闭拼写检查

注意:浏览器定义了多文本编辑命令,使用dicument,execCommand()可以调用(比如copy,selectAll等命令;在使用execCommand()方法时,界面元素的contenteditable属性值不能设置为true,否则会影响copy命令)

<div contenteditable="true" spellcheck="true"></div>

<button>提交</button>

<script type="text/javascript">

let div = documentquerySelector('div');

let btn = documentquerySelector('button');

btnonclick = function(){

consolelog(divinnerText);

}

</script>

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

三、JS动画

原理:通过定时器setInterval()不断移动盒子位置。

例:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style type="text/css">

box1{

width: 200px;

height: 200px;

position: absolute;

top: 50px;

background-color: #3B78DD;

}

box2{

width: 100px;

height: 100px;

position: absolute;

top: 400px;

background-color: lightblue;

}

button{

position: absolute;

top: 300px;

}

</style>

</head>

<body>

<div class="box1"></div>

<div class="box2"></div>

<button>点击移动box2</button>

<script type="text/javascript">

let box1 = documentquerySelector('box1');

let box2 = documentquerySelector('box2');

let btn = documentquerySelector('button');

function animate(obj, disdance, speed){

clearInterval(objtimer);

objtimer = setInterval(function(){

let moving = objoffsetLeft;

moving += 1;

objstyleleft = moving + 'px';

if(moving > disdance){

clearInterval(objtimer);

}

},speed);

}

animate(box1,300,5);

btnonclick = function(){

animate(box2,400,3);

}

</script>

</body>

</html>

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

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

以上就是关于VB 怎样获取键鼠无动作时间 (100分送上)全部的内容,包括:VB 怎样获取键鼠无动作时间 (100分送上)、VB获取网络时间、js获取可视区域文字的方法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9349316.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存