写一个Java函数,计算输入字符串需要多少键盘按输出字符串.假设输入字符串只有小和大字母英语字母,空格和标记. 例子: "abcdeF"-> 7 (因为要输入"F",你需要按"Shift"). "ABCDEf"-> 7 (你按"Shift"然后输入"ABCDE". 这就是六次点击. 然后你释放shift并按"f". 因此,7次点击.)
Here's a possible implementation in Java:

```java
public static int calculateKeypress(String str) {
    // Define arrays for upper and lower case letters
    char[] upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    char[] lowerLetters = "abcdefghijklmnopqrstuvwxyz".toCharArray();
    
    int keypresses = 0;
    boolean shiftDown = false;
    
    for (char ch : str.toCharArray()) {
        if (ch == ' ') {
            keypresses++; // space is a separate button
        } else if (ch == '.' || ch == ',' || ch == '!' || ch == '?') {
            keypresses++; // punctuation is a separate button
        } else if (containsChar(upperLetters, ch)) {
            if (!shiftDown) {
                keypresses++; // need to press shift first for upper case letters
                shiftDown = true;
            }
            keypresses++;
        } else {
            if (shiftDown) {
                keypresses++; // upper case mode needs to be turned off for lower case letters
                shiftDown = false;
            }
            keypresses++;
        }
    }
    return keypresses;
}

private static boolean containsChar(char[] arr, char ch) {
    for (char c : arr) {
        if (c == ch) {
            return true;
        }
    }
    return false;
}
```

The `calculateKeypress` function takes a string as input and returns the number of key presses needed to type that string. 
The function iterates over every character in the string, and counts how many key presses are needed for each character based on the rules given in the problem description.
A boolean variable `shiftDown` keeps track of whether the Shift key is currently being held down. If an upper case letter is encountered while `shiftDown` is false, then the Shift key needs to be pressed first before typing that letter, and vice versa when going from upper case to lower case.
The `containsChar` helper function is used to check whether a given character is a member of an array of characters.