Skip to content

Instantly share code, notes, and snippets.

@hirosof
Created August 19, 2012 21:38
Show Gist options
  • Select an option

  • Save hirosof/3397892 to your computer and use it in GitHub Desktop.

Select an option

Save hirosof/3397892 to your computer and use it in GitHub Desktop.
WaitPressKey.cppのHSP版
#include "user32.as"
#include "winmm.as"
#module
#deffunc WaitPressKey int virtualkeycode , int timeout
mref retkey , 64
flag = 0
timeBeginPeriod 1
timeGetTime
timed = stat
repeat
if (virtualkeycode == -1){
repeat 256
//OEM形のコードはスキップ
if((cnt>=0xE9 && cnt<=0xF5) || cnt==0xE1 || cnt==0xE3 || cnt==0xE4 || cnt==0xE6) : continue
GetAsyncKeyState cnt
if(stat & 0x8000){
flag = 1
retkey = cnt
break
}
loop
}else{
GetAsyncKeyState virtualkeycode
if(stat & 0x8000) : flag = 1 : retkey = virtualkeycode
}
await 1
if flag : break
stat_data = stat
timeGetTime
timen = stat
retkey = stat_data
if (timeout == 0 || ((timeout > 0) && ((timen - timed) >=timeout))) : retkey = -2 :break
loop
stat_data = stat
timeEndPeriod 1
retkey = stat_data
return
#deffunc WaitPressKeyEx int isAnd , array virtualkeycodes , int numberofcodes , int timeout
if(numberofcodes <= 0) : checknums = length(virtualkeycodes) : else : checknums = numberofcodes
mref retkey , 64
timeBeginPeriod 1
timeGetTime
timed = stat
repeat
andendflag = 1
orendflag = 0
repeat checknums
GetAsyncKeyState virtualkeycodes(cnt)
keystate = (stat & 0x8000) >> 15
if(isAnd){
andendflag *= keystate
retkey = 0
if(andendflag == 0):break
}else:if(keystate){
orendflag = 1
retkey = virtualkeycodes(cnt)
break
}
loop
if((isAnd && andendflag) || (isAnd==0 && orendflag)) : break
stat_data = stat
timeGetTime
timen = stat
retkey = stat_data
if (timeout == 0 || ((timeout > 0) && ((timen - timed) >=timeout))) : retkey = -2 :break
await 1
loop
stat_data = stat
timeEndPeriod 1
retkey = stat_data
return
#global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment