WaitforKey - Special Characters and CPU Usage
Keywords: waitforkey CPU
Question, RE: Special Characters:
I was trying to build a keyboard macro
utility and I'm having a difficult time
recognizing some characters("*","#" and
maybe more). I was just using WordPad as my
Active Window for testing. It can find "F12"
but not "*"?
Here's the code:
While 1
k = WaitForKey("*", "{F12}", "{INSERT}", "", "")
;Debug(1)
switch k
case 1
Message("WaitForKey", "You pressed the * key")
break
case 2
Message("WaitForKey", "You pressed the F12 key")
break
case 3
Message("WaitForKey", "You pressed the Insert key")
Break
endswitch
EndWhile
Exit
Also, is it just me, or does WaitForKey chew up almost 100% of the CPU?
Answer:
Use the following code instead:
k = WaitForKey("+8","{F12}", "{INSERT}", "", "")
- In 16 bit WinBatch running on a 32 bit system, WaitForKey will chew up LOTS of CPU
- In 32 bit WinBatch on a 32 bit system it will LOOK like it is chewing up lots of CPU be is not really. Try
a real world test like use Excel or Word and see if you can notice a slowdown.
Another Question:
Question:
I am adding a new application for our users.
It's a TCP/IP 3270 product called TNHOST. Prior to this we were using a UNIX SNA
emulation to get to the mainframe. I have defined ALT 1, ALT 2, ALT 3, and ALT 4 to
switch between the UNIX and TNHOST sessions and an image display window. I use a
WINBATCH script that runs in background waiting for these keystrokes. Everything
works fine if the mouse is positioned in one of the UNIX windows. If the mouse is
positioned in the TNHOST window or outside of the UNIX windows and the current
active window is TNHOST, the keystrokes are not
recognized by WINBATCH. I am using the 16 bit
versions of all products in a Windows 95 environment.
Answer:
Wait for Key simply looks at a snapshot of the windows message stream.
The key has to be pressed when WinBatch checks (it is a polling operation - fast hits can
be missed). And the Window in question has to use the standard windows methods of
accessing keystrokes. For example DOS windows do not.
WaitForKey and NT interacting with Java Applets
Question:
Several weeks ago I posted a message about WaitforKey and NT resources showing 100% utilization. AT that time I
was told that NT was reporting resource utilization incorrectly. I did a few simple tests and it appeared that the machine
was running correctly. I deployed the app and all of a sudden my users were complaining that JAVA appletes where
hanging when attempting to load into IE 5.0. The removal of the app running WaitforKey allowed the JAVA appletes to
load as normal. So, whats UP?.
Answer:
Gee. I don't know. Apparently some strange interaction between the WaitForKey and the JavaApplets loading.
Try adding this code to the top of
your script. (This code assumes that you have it compiled to an exe and there are no
passed parameters to your exe. It may need
to be modified accordingly. The trick
employed here is to vastly reduce the priority of the WinBatch job.
if param0==0
IntControl(51,64,0,0,0) ; Idle prioirty class
Run(WinExeName(""),"REALLYDOIT")
exit
endif
Article ID: W13113
Filename: WaitforKey and CPU Usage.txt
File Created: 1999:08:26:10:57:06
Last Updated: 1999:08:26:10:57:06