ScanCodeToRawKey

About Monkey 2 Forums Monkey 2 Development ScanCodeToRawKey

This topic contains 7 replies, has 4 voices, and was last updated by  bigand 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #11519

    bigand
    Participant

    I have just updated to V1.1.08 and the ScanCodeToRawKey now throws this error:

    “Error : Internal declaration ‘ScanCodeToRawKey’ cannot be accessed from here.”

    The code still works fine in V1.1.07. This is on Mac OS Sierra 10.12.6.

    A quick example:

    Function AnyKey:Key()
    Local i:Int,k:Key

    For i=0 To 255
    k=Keyboard.ScanCodeToRawKey(i)
    If Keyboard.KeyDown(k)
    Return(k)
    Endif
    Next
    Return(Key.None)
    End

    #11527

    Mark Sibly
    Keymaster

    ScanCodeToRawKey is an internal function – it has been @hidden from docs, and should therefore be considered ‘use art your own risk’.

    I’ve had to make it public in the past as monkey2 lacked an ‘Internal’ directive, ie: decls are visible to other module members only. But that has recently been added to monkey so I have made several methods/functions Internal.

    What are you actually using it for?

    #11528

    bigand
    Participant

    Thanks for the info Mark.

    Just using like the function above. Couldn’t think of a better way to check for “Any Key” being pressed.

    Its not critical at all, it was just useful.

    #11529

    nerobot
    Participant

    @bigand

    You can specify own application key filter and grab any keys:

    #11530

    AdamStrange
    Participant

    @nerobot erm. ok. why?
    Why not use:
    Method OnKeyEvent( event:KeyEvent ) Override
    end method

    Which is the normal way of trapping key codes. But not in this case cause he wants to check if a key is pressed, hence using scancode

    #11531

    nerobot
    Participant

    You can use App.KeyEventFilter in any place, but OnKeyEvent only inside of View-based classes like Window.

    What if my key-logic know nothing about window?

    #11535

    Mark Sibly
    Keymaster

    Just using like the function above. Couldn’t think of a better way to check for “Any Key” being pressed.

    You don’t need to pass rawkeys to KeyDown, you can just pass a plain ‘virtual’ key, eg: ‘Key.A’ or ‘Key.Z’ etc.

    But to pass an int ‘key’ to KeyDown you’ll need to convert it to a ‘Key’ type first – in fact, this is probably all your use of ScanCodeToRawKey is really achieving here – In this case, it doesn’t really matter whether you pass virtual keys or rawkeys or banana keys to KeyDown, since you’re just throwing every possible value at it!

    To convert an int to a key, you can ‘Cast<Key>( n )’ it – example below. But as people have noted there are other ways to do this too.

    #11591

    bigand
    Participant

    Thanks again to all and I hadn’t even thought about casting. Such a simple change and totally negated using ScanCodeToRawKey.

    Shows how little I know the language.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.