You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.3 KiB
63 lines
1.3 KiB
<template>
|
|
<div :class="keyboardClass" id="keyboard"></div>
|
|
</template>
|
|
|
|
<script>
|
|
import Keyboard from 'simple-keyboard'
|
|
import 'simple-keyboard/build/css/index.css'
|
|
|
|
export default {
|
|
name: 'SimpleKeyboard',
|
|
props: {
|
|
keyboardClass: {
|
|
default: 'simple-keyboard',
|
|
type: String,
|
|
},
|
|
input: {
|
|
type: String,
|
|
},
|
|
hideKeyBoard: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
},
|
|
data: () => ({
|
|
keyboard: null,
|
|
}),
|
|
mounted() {
|
|
this.keyboard = new Keyboard(this.keyboardClass, {
|
|
onChange: this.onChange,
|
|
onKeyPress: this.onKeyPress,
|
|
})
|
|
},
|
|
methods: {
|
|
onChange(input) {
|
|
this.$emit('onChange', input)
|
|
},
|
|
onKeyPress(button) {
|
|
this.$emit('onKeyPress', button)
|
|
|
|
/**
|
|
* If you want to handle the shift and caps lock buttons
|
|
*/
|
|
if (button === '{shift}' || button === '{lock}') this.handleShift()
|
|
},
|
|
handleShift() {
|
|
let currentLayout = this.keyboard.options.layoutName
|
|
let shiftToggle = currentLayout === 'default' ? 'shift' : 'default'
|
|
|
|
this.keyboard.setOptions({
|
|
layoutName: shiftToggle,
|
|
})
|
|
},
|
|
},
|
|
watch: {
|
|
input(input) {
|
|
this.keyboard.setInput(input)
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
<style lang="scss" scoped></style>
|