泡泡小顽童 发表于 2011-4-21 12:32:03

请教_ispressed函数监测功能键{F12}被按下的方法

网上看到_ispressed函数的第一个参数都是按键的ASCII码,但是没有找到F12的使用方法,试过"{F12}"也不行。请大家指点,谢谢!

editcue 发表于 2011-4-22 19:56:17

_IsPressed函数的原理其实就是调用User32.dll的GetAsyncKeyState函数。Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
      ; $hexKey must be the value of one of the keys.
      ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
      Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
      If @error Then Return SetError(@error, @extended, False)
      Return BitAND($a_R, 0x8000) <> 0
EndFunc   ;==>_IsPressed详细按键的代码表可以到这里查看Virtual-Key Codes
使用方法比如:
F12的十六进制代码是0x7B
那么_IsPressed的按键码就是7B

happytc 发表于 2011-4-22 22:06:31

网上看到_ispressed函数的第一个参数都是按键的ASCII码,但是没有找到F12的使用方法,试过"{F12}"也不行。请 ...
泡泡小顽童 发表于 2011-4-21 12:32 http://www.autoitx.com/images/common/back.gif

include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("7B", $dll) Then
      MsgBox(0,"_IsPressed", "F12 Key Pressed")
      ExitLoop
    EndIf
WEnd
DllClose($dll)

当然若是用SCite来做au3的Editor,其本身会截掉F12消息。

pusofalse 发表于 2011-4-23 13:27:58

本帖最后由 pusofalse 于 2011-4-23 13:35 编辑

这又不是消息传递,就算scite截断{f12}按键消息,那又会怎样呢?难道_IsPressed函数会因此失效了吗?~

republican 发表于 2011-4-23 13:33:51

回复 4# pusofalse

难道是传说中的错别字?^_^

泡泡小顽童 发表于 2011-4-28 21:13:21

谢谢,学习了。好几天没上了。

happytc 发表于 2011-4-28 23:18:12

这又不是消息传递,就算scite截断{f12}按键消息,那又会怎样呢?难道_IsPressed函数会因此失效了吗?~
pusofalse 发表于 2011-4-23 13:27 http://www.autoitx.com/images/common/back.gif

你理解错了,不是_IsPressed函数没有效了,而是在SCite直接试的话,因被截了,会有时没有想要的效果,而变成SCite没有语法高亮的效果,只是提示楼主一下呀
页: [1]
查看完整版本: 请教_ispressed函数监测功能键{F12}被按下的方法