Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit cf7a129

Browse files
committed
Move up the keyboard up method
1 parent 07122cf commit cf7a129

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

common/keyboard.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ func (k *Keyboard) down(key string) error {
9999
return nil
100100
}
101101

102+
func (k *Keyboard) up(key string) error {
103+
keyInput := keyboardlayout.KeyInput(key)
104+
layout := keyboardlayout.GetKeyboardLayout(k.layoutName)
105+
if _, ok := layout.ValidKeys[keyInput]; !ok {
106+
return fmt.Errorf("'%s' is not a valid key for layout '%s'", key, k.layoutName)
107+
}
108+
109+
keyDef := k.keyDefinitionFromKey(keyInput)
110+
k.modifiers &= ^k.modifierBitFromKeyName(keyDef.Key)
111+
delete(k.pressedKeys, keyDef.KeyCode)
112+
113+
action := input.DispatchKeyEvent(input.KeyUp).
114+
WithModifiers(input.Modifier(k.modifiers)).
115+
WithKey(keyDef.Key).
116+
WithWindowsVirtualKeyCode(keyDef.KeyCode).
117+
WithCode(keyDef.Code).
118+
WithLocation(keyDef.Location)
119+
if err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {
120+
return fmt.Errorf("unable to mouse down: %w", err)
121+
}
122+
123+
return nil
124+
}
125+
102126
func (k *Keyboard) insertText(text string) error {
103127
action := input.InsertText(text)
104128
if err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {
@@ -227,30 +251,6 @@ func (k *Keyboard) typ(text string, opts *KeyboardOptions) error {
227251
return nil
228252
}
229253

230-
func (k *Keyboard) up(key string) error {
231-
keyInput := keyboardlayout.KeyInput(key)
232-
layout := keyboardlayout.GetKeyboardLayout(k.layoutName)
233-
if _, ok := layout.ValidKeys[keyInput]; !ok {
234-
return fmt.Errorf("'%s' is not a valid key for layout '%s'", key, k.layoutName)
235-
}
236-
237-
keyDef := k.keyDefinitionFromKey(keyInput)
238-
k.modifiers &= ^k.modifierBitFromKeyName(keyDef.Key)
239-
delete(k.pressedKeys, keyDef.KeyCode)
240-
241-
action := input.DispatchKeyEvent(input.KeyUp).
242-
WithModifiers(input.Modifier(k.modifiers)).
243-
WithKey(keyDef.Key).
244-
WithWindowsVirtualKeyCode(keyDef.KeyCode).
245-
WithCode(keyDef.Code).
246-
WithLocation(keyDef.Location)
247-
if err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {
248-
return fmt.Errorf("unable to mouse down: %w", err)
249-
}
250-
251-
return nil
252-
}
253-
254254
// Down
255255
func (k *Keyboard) Down(key string) {
256256
rt := k6common.GetRuntime(k.ctx)

0 commit comments

Comments
 (0)