Wrong "provessormode" with MultiKey

General FreeBASIC programming questions.
Post Reply
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Wrong "provessormode" with MultiKey

Post by Jawade »

Code: Select all

Do
  For a As Integer = 1 To 93
    If MultiKey(a) Then Print a;
  Next
Loop
If I start this code, when the CPU is in a wrong mode, the output is: 1 2 3 4 etc.
If I start the pc, he is in the good mode, but after a cople of hours, he goes in
the wrong mode. Programs who use MultiKey, are getting problems.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wrong "provessormode" with MultiKey

Post by MrSwiss »

Sorry, but that code of yours, simply makes no sense at all, to start with.
Maybe the stuff below does, what you want (I'm simply guessing here):

Code: Select all

Dim As UInteger a
Dim As String   s = ""

Width 120, 25       ' preset console size

For a = 32 To 127   ' first chr() = space (0 to 31 = unprintable)
    s += Chr(a)     ' put character by character into string
Next

Print " String created by numbers:"
Print : Print s : Print ' print the string chreated
Print " any key press --> EXIT! ";

Sleep
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wrong "provessormode" with MultiKey

Post by dodicat »

perhaps include a sleep 1,1 -- give you cpu a little break.

Code: Select all

Do
    
    For a As Integer = 1 To 93
        
        If Multikey(a) Then Cls: Locate 3,3,0: Print a;
    Next
    Sleep 1,1
    Loop until multikey(1) 'esc 
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Wrong "provessormode" with MultiKey

Post by Jawade »

Sorry, but with my code if I no press a key, the output is 1 2 3 4 5 6 7 ... 92 93 1 2 3 4 etc.
In the normal mode, there is no output, but in the wrong mode just like above. Sometimes
he stays hours in then normal mode, but sometimes after hours he goes in then wrong mode
and prints the output witout I press any key.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wrong "provessormode" with MultiKey

Post by MrSwiss »

Please, to get somewhere, explain what your code is used for "what do you want it, to do".
And, secondly, define it's output as below specified.

This under any possible condition:
  • if it's OK = "expected result"
    if it's NOT OK = "expected result"
Otherwise, we can't help ... it's as simple as that!
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Wrong "provessormode" with MultiKey

Post by Jawade »

If I start the pc, everything is normal. If I start my code, there is no output. But sometimes,
after hours, the pc goes in a wrong mode, and then, if I start my code, there is constantly
an output, 1 2 3 4 5 ... 92 93 1 2 3 etc. If I want the normal mode, I need to restart the pc.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wrong "provessormode" with MultiKey

Post by MrSwiss »

OK, seems like dodicat was *on the right track*, so to speak.

You'll have to use a sleep (of a certain length) to *NOT hog* the CPU.
Since this is probably the cause, for the *mode* switch, as you call it.

the following will only print, if a key (except, [ESC]) has been pressed:

Code: Select all

Dim As String   a

Do
    a = InKey()
    If Len(a) Then
        Cls
        Locate 3, 3, 0
        Print a;
    End If
    Sleep 100, 1  ' waits for 0.1 Second and, at the same time, releases CPU
Loop until a = Chr(27) ' quit code = [ESC] pressed
Note: some key's can't be printed.
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Wrong "provessormode" with MultiKey

Post by Jawade »

I dont need an other program-way for my problem, because the problem stays. The only
way is a reboot. My program is meant for to make the problem visual. I can make a program
which dont have a problem with the problem :-) but there are many programs who have
a problem with the 'mode' problem.

Shoult there a program be possible who capsizing the problem?
Post Reply