B4J Question Problem sending the @ character

claudiob4

Member
Licensed User
Longtime User
Hi all, I can't send the @ character with any of the steps below. Does anyone have the solution?
Thank you


Dim robot As JavaObject
robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)

Dim KeyCode As JavaObject
KeyCode.InitializeStatic("javafx.scene.input.KeyCode")


robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
'not work

robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT_GRAPH")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT_GRAPH")))
' not work

robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT")))
'not work
 
Hi all, I can't send the @ character with any of the steps below. Does anyone have the solution?
Thank you


Dim robot As JavaObject
robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)

Dim KeyCode As JavaObject
KeyCode.InitializeStatic("javafx.scene.input.KeyCode")


robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
'not work

robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT_GRAPH")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT_GRAPH")))
' not work

robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT")))
'not work

Perhaps this code is what you need

B4X:
Dim robot As JavaObject
robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)

Dim KeyCode As JavaObject
KeyCode.InitializeStatic("javafx.scene.input.KeyCode")
   
robot.RunMethod("keyPress", Array(KeyCode.GetField("SHIFT")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("DIGIT2")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("DIGIT2")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("SHIFT")))
 
Upvote 0
Thanks for the reply. I work on an Italian keyboard and unfortunately this sequence produces the character " but not @. On my keyboard the combination is ALT_GRAPH ò . But the character ò does not have a keycode in the table. How to do it?
 
Upvote 0
The problem could be that you can use a country specific keyboard in combination with an other language while javafx looks to the language of the OS, not to the connected keyboard.
Code:
import java.awt.im.*; 
  public class _Test 
  { 
  public static void main(String[] args) 
  { 
  InputContext context = InputContext.getInstance(); 
  System.out.println(context.getLocale().toString()); 
  } 
  }
What keyboard language is reported?
 
Upvote 0
Thanks for the reply. I work on an Italian keyboard and unfortunately this sequence produces the character " but not @. On my keyboard the combination is ALT_GRAPH ò . But the character ò does not have a keycode in the table. How to do it?
Try this code
B4X:
    robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD0")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD0")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD6")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD6")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD4")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD4")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT")))
 
Upvote 0
The Italian keyboard code for a @ character is 0264, so teddybear code must be:

Code:
    robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD0")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD0")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD2")))         ' <== select Italian keyboard
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD2")))     '
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD6")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD6")))
    robot.RunMethod("keyPress", Array(KeyCode.GetField("NUMPAD4")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("NUMPAD4")))
    robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT")))
 
Upvote 0
All of these solutions don't work. However I found a way to fix it using the jAWTRobot.

Code:
    Dim jRobot As AWTRobot
    
    'Suppose we need to send a string containing the character @'
    
    jRobot.RobotPaste("[email protected]",50)

Thanks for your attention
 
Upvote 0
Back
Top