Keyboard.asynckeydown works on this Mac, but not that

Like others with similar issues, I am tinkering with an old Carbon Mac/Windows game of mine. Before getting into playing with the code, I found that the game still runs well on my 2009 Mac Pro (Sierra), and even on Windows.

When I run it on my 2014 MacBook Pro (also Sierra), I get nothing from the arrow keys or space bar, operated by the player. I’m pretty sure I HAVE run the game on this machine before, albeit two-three OSs ago.

The game itself got the keys from the KeyTest method of the dearly departed SpriteSurface. Any rewrites would forgo that. However, I am finding that I cannot get even sample projects to work which use KeyBoard.AsynckeyDown. On the other hand, behavior on the desktop Mac (and the Windows machine) is as expected. Stuff like asyncCommandKey, etc. seem to be fine.

I find this baffling.

I suspect your problem lies In the outdated Sprite Surface. Like many others, I continue to use ASyncKeyDown with no problem. Please post a piece of code which does not return the results you expect, and I, along with others, will test it.

Code ?

Also if the LANGUAGE region of the keyboards in question are different that may account for the issue as well… Keycodes ARE NOT all the same (the LR even says its documents is for English keyboards only)

On Mac, keycodes are not localized. They refer to fixed positions on the keyboard. So for instance Q in the US keyboard becomes A in a French layout.

But I never encountered problems with the Keyboard object. I strongly suspect some issue in the program.

Thanks all. Repeating for clarity, I am not asking for troubleshooting help on the obsolete SpriteSurface control. I only mentioned that because, under Sierra, the program still works correctly on my desktop Mac, but not the laptop. Spritesurface did not use the keyboard object as such; it had its own method called “KeyTest.”

My point is that I don’t have any better luck using asyncKeyDown, on the MacBook Pro. I use the example code from the Timer documentation in the LR. Action event, Timer period is 100:

If Keyboard.AsyncKeyDown(123) Then
Label1.Text = “left arrow key”
End If
If Keyboard.AsyncKeyDown(124) Then
Label1.Text = “right arrow key”
End If
If Keyboard.AsyncKeyDown(125) Then
Label1.Text = “down arrow key”
End If
If Keyboard.AsyncKeyDown(126) Then
Label1.Text = “Up arrow key”
End If

This works fine when running remotely on a Windows machine. My desktop Mac is not where I am right now, but I have a feeling it would work there too (like the SpriteSurface did.)

On the MacBook Pro I just get an annoying beep when I press the keys. I can eliminate that by trapping the keyDown event, or by giving the focus to a textfield or something, but that does no good.

The same issue appears in the Asteroids clone game that comes with Xojo in the examples, which uses AsyncKeyDown in a timer.

As to possible hardware issues, I am not noticing any problems using these keys (arrow keys when scrolling, etc.)

Thanks again. Oh, I guess I have to make an avatar now, too :slight_smile:

Jerry

is this is a KEYDOWN event?
if so, use

select case key
case chr(28)
label1.text="arrow"
case chr(29)
label1.text="arrow"
case chr(30)
label1.text="arrow"
case chr(31)
label1.text="arrow"
end select

I never remember WHICH arrow is which, but it is consistent for all keyboards, all operating systems

Uh, you are not testing this via a remote connection, do you? Because that’d be not unlikely to fail, as it might insert keydown events into the event queue directly without actually updating the low level key map that asynckeydown may be checking.

That’s because you are not returning True in the KeyDown event to signal that you handled that key.

Actually I did that (I inelegantly used the phrase "trapping the KeyDown event.)

It is the other way around for with me. It works when sending to the Windows desktop machine which is running the debugger stub. It does not work when running directly on the MacBook Pro. I’ll have a chance to run on the Mac Pro later today (the machine that, as I originally said, can even still properly handle the keys with the old SpriteSurface :slight_smile: )

there is very little reason (my opinion) to hassle with using AsyncKeyDown() especially in a KEYDOWN event

[quote=313965:@Dave S]is this is a KEYDOWN event?
if so, use[/quote]

No, the code I was using (again, straight from the language reference) is in the action event of a timer.

Your code works, and may in fact be a viable alternative. Right now I’m just hung up on the issue that I can’t get keyboard.asynckeydown to work at all on this particular machine.

Just want to make clear that I wasn’t using this code in the KeyDown event. :slight_smile:

There was a question above about remote debugging. The keyboard module taps AFAIK directly into the hardware. In remote debugging, chances are it cannot work.

I would start by doing a very small project with only the timer that manages AsyncKeydown with something like :

For i as Integer = 0 to 255 If Keyboard.AsyncKeyDown(i) then system.debuglog "AsyncKeyDown "+hex(i) end if next

And run that directly on the MBP.

If indeed nothing happens, then file a bug report.

[quote=314108:@Michel Bujardet]There was a question above about remote debugging. The keyboard module taps AFAIK directly into the hardware. In remote debugging, chances are it cannot work.

I would start by doing a very small project with only the timer that manages AsyncKeydown with something like :

For i as Integer = 0 to 255 If Keyboard.AsyncKeyDown(i) then system.debuglog "AsyncKeyDown "+hex(i) end if next

And run that directly on the MBP.

If indeed nothing happens, then file a bug report.[/quote]

Perhaps I haven’t been clear, but I have been running the IDE on the MBP from the beginning. The only remote debugging (we’ve gotten sidetracked on this issue) has been when I’ve sent the program over to a Windows machine…where it DID work.

Now I am at my other location (I’m in the middle of moving) where I have my 2009 Mac Pro. My test project (simple timer example from the LR) works as expected. Also here I have another laptop, a 2009 MacBook. Works here too. Both are running the current Sierra like the MBP.

Then again, both of these older machines can also satisfactorily run my old SpriteSurface game, but that’s another story :slight_smile:

So, the end result is that I have one Mac out of three (it happens to be the newest one) that doesn’t appear to recognize Keyboard.Asynckeydown() at all. When I return to that machine, Michel, I shall try YOUR code and see what happens.

BTW here is a slightly different code in a 100 ms multiple timer, to avoid getting several message each time a key is pressed :

Sub Action() Handles Action static previousi as integer For i as Integer = 0 to 255 If Keyboard.AsyncKeyDown(i) and previousi <> i then system.debuglog "AsyncKeyDown "+hex(i)+" ("+str(i)+")" previousi = i end if next End Sub

If it did not work, that would call for a bug report.

Thanks to all who replied here. I finally had a brainwave from which I quickly found the solution. The factor that made my MacBook Pro different from the other Macs was that it had Webroot Security installed. Webroot’s “Secure Keyboard Entry” feature, which is on by default, is what caused the failure to get a return from Keyboard.AsyncKeyDown (). Disabling this feature in Webroot was all it took.

While my Windows 10 machine also runs Webroot, the issue did not present itself there.

Again, I appreciate all of your efforts, and I got additional useful information from your comments and sample code. I regret that this turned out to be that proverbial wild goose chase.

It is very good to know that Webroot prevents AsyncKeyDown to work. Now if I have MBP customers complaining that my Char Menu does not work, I know where it comes from.

Not just MBP, of course. I had previously wiped my desktop machine, and done a clean install of Sierra. When I reinstalled Webroot on it, I reproduced the failure :slight_smile: