Val编程-按键响应模式

由于Val是通过语句gotoxy函数来进行光标移动的,不支持触摸屏与鼠标,因此对于其界面编程有很大的局限。
一般有下面几种模式来进行编程。
1.按键响应模式(中断模式)
2.轮询模式

一般推荐使用按键响应模式。其原理是对于有按键按下时,界面进行相应的刷新。
常用按键有F1,F2,F3,F4,F5,F6,F7,F8,Enter,ESC, up,down,left,right 这14个按键进行响应。

Val代码
 1 begin
 2   //清除界面
 3   cls()
 4   //界面刷新函数
 5   call OnRefreshScreen()
 6   
 7   //如果不退出,则进行一直在循环
 8   while l_bExit
 9     //默认刷新界面
10     l_bRefresh=true
11     //获取按键值
12     l_nKeyValue=getKey()
13     switch l_nKeyValue
14       //按键Esc响应函数
15       case 255
16         call OnEsc()
17       break
18       //按键导航键向上响应函数
19       case 261
20         call OnUp()
21       break
22       //按键导航键向下响应函数
23       case 266
24         call OnDown()
25       break
26       //按键导航键向左响应函数
27       case 264
28         call OnLeft()
29       break 
30       //按键导航键向右响应函数
31       case 268
32         call OnRight()
33       break    
34       //按键回车键响应函数
35       //******************
36       //常用
37       case 270
38         call OnEnter()
39       break
40       //按键功能键F1响应函数
41       case 271
42         call OnF1()
43       break 
44       //按键功能键F2响应函数      
45       case 272
46         call OnF2()
47       break
48       //按键功能键F3响应函数      
49       case 273
50         call OnF3()
51       break  
52       //按键功能键F4响应函数      
53       case 274
54         call OnF4()
55       break 
56       //按键功能键F5响应函数      
57       case 275
58         call OnF5()
59       break
60       //按键功能键F6响应函数      
61       case 276
62         call OnF6()
63       break   
64       //按键功能键F7响应函数      
65       case 277
66         call OnF7()
67       break
68       //按键功能键F8响应函数      
69       case 278
70         call OnF8()
71       break        
72       
73       default
74         l_bRefresh=false
75       break
76       
77     endSwitch
78     
79     if l_bRefresh
80       
81       //界面刷新函数
82       call OnRefreshScreen()
83       
84     endIf
85     delay(0)
86   endWhile
87   
88   
89 end

 

说明:
1.对于获取按键函数get()与getkey()的区别
2.getkey()按键不灵敏的说明
3.界面闪屏的问题的说明与处理

posted @ 2013-03-21 09:25  竖毛杰  阅读(451)  评论(0编辑  收藏  举报