LoginSignup
2
2

More than 5 years have passed since last update.

HSPのCUIで何か選ばせるやつ

Posted at

HSPのコンソールで何か選ばせることがあるならこういうようにしたらユーザービリティあっていい感じかなって。

#runtime "hsp3cl"

#module Program
    #uselib "crtdll"
    #cfunc getch "_getch"
    #cfunc kbhit "_kbhit"

    ;カーソルの移動
    #defcfunc move int _ch,int max
        if _ch=$4b :cursol-- ;左
        if _ch=$4d :cursol++ ;右
        if cursol<0 :cursol=0
        if max-1<cursol :cursol=max-1
    return cursol

    ;カーソルの表示
    #deffunc cursolShow array items,int csl
        dim slct,length(items)
        slct(csl)=1
        s=""
        foreach items
            if slct(cnt): s+=strf("[%s]",items(cnt)): else: s+=strf(" %s ",items(cnt))
        loop
        mes strf("%s\r",s),1

    return

    #deffunc main
        items="壱","弍","参","四","五","六","七","八","九","拾"
        cursolShow items,0
        repeat
            if kbhit() {
                ch=getch()
                if ch=$0d {
                    mes ""
                    break
                }
                if ch=$e0 {
                    cursolShow items,move(getch(),length(items))
                }
            }
        loop
        mes strf("SelectedItem: %s",items(cursol))
    return
#global
main
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2